kittykatattack / sound.js

A micro-library to load, play and generate sound effects and music for games and interactive applications
300 stars 44 forks source link

sounds.load() fails for offline pages #9

Open sebhaase opened 8 years ago

sebhaase commented 8 years ago

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.

kittykatattack commented 8 years ago

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

sebhaase commented 8 years ago

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

kittykatattack commented 8 years ago

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.)

sebhaase commented 8 years ago

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 ...?