sound.js icon indicating copy to clipboard operation
sound.js copied to clipboard

sounds.load() fails for offline pages

Open sebhaase opened this issue 9 years ago • 4 comments

I'm getting sound.js:570 XMLHttpRequest cannot load file:///Users/...m-0.wav. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Can sound.load() be told not to use ajax ? Thanks.

sebhaase avatar Jun 15 '16 09:06 sebhaase

Are you running the file in a webserver? XHR calls only work from inside webservers for browser security reasons.

kittykatattack avatar Jun 15 '16 12:06 kittykatattack

no. think of this as a "save complete web page" ... i.e. index.html + resources (including js and wav files)

sebhaase avatar Jun 15 '16 13:06 sebhaase

Unfortunately, even if your application is off-line, you still need to run a webserver in your project root directory for XHR (Ajax) loading of sound files. (The WebAudio API requires XHR to decode sound files.)

kittykatattack avatar Jun 15 '16 16:06 kittykatattack

What if I had the (local) file as part of the HTML DOM, i.e. <audio id=aaa> <source src="...m-0.wav"> </audio> ? Now I should even be able to play it like this: $("#aaa")[0].play() Could I somehow adapt this to the source.js infrastructure ...?

sebhaase avatar Jun 15 '16 19:06 sebhaase