carregandoAudio.js 471 B

1234567891011121314151617181920212223
  1. // Carregando audios - fetch api e HTMLAudioElement
  2. function loadAudios() {
  3. var init = {
  4. mode: "same-origin", // por padrão é "cors"
  5. };
  6. audiosUrl.forEach((url) => {
  7. fetch(url, init)
  8. .then(response => response.blob())
  9. .then(function (myBlob) {
  10. audios.push(new Audio(URL.createObjectURL(myBlob))); //HTMLAudioElement
  11. })
  12. });
  13. }
  14. function playAudio() {
  15. audios[0].play();
  16. }
  17. let audios = []
  18. let audiosUrl = [
  19. "audio/beep.mp3"
  20. ];