mdn / webaudio-examples

Code examples that accompany the MDN Web Docs pages relating to Web Audio.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
Creative Commons Zero v1.0 Universal
1.28k stars 433 forks source link

audio-basics fails out of the box #35

Closed madc0w closed 2 years ago

madc0w commented 4 years ago

pushing the play button results in:

index.html:81 Uncaught (in promise) DOMException: The element has no supported sources.

here:

audioElement.play();

Leokuma commented 4 years ago

That's probably because you're opening index.html directly from the filesystem.

If you access it through a web server (e.g. Apache), it works.

I couldn't figure out how to make it work without a web server.

chrisdavidmills commented 4 years ago

I couldn't figure out how to make it work without a web server.

You can't, due to browser security policies.

teoli2003 commented 2 years ago

Closing. These demos don't work from a file: filesystem (security policies). To test locally, there are extensions to common code editors, like VSCode, that allow opening a page in a local web server. (I use this to test these pages when I adapted them to modern JS)