kittykatattack / hexi

Make games the fun way!
MIT License
551 stars 83 forks source link

Issue with loading sound- Uncaught DOMException: Failed to read the 'responseText' ... #38

Open se7enTale opened 7 years ago

se7enTale commented 7 years ago

Loading sound file with Hexi seems like did not work for me!

Trying to load a sound file in WAV format like this:

let thingsToLoad = ["sounds/music.wav"];

And caught up this error message in console:

"Uncaught DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). at Resource._xhrOnLoad (file:///C:/Users/User/Desktop/Hexi%20-%20Copy/library/hexi.js:6041:65)"

Same with MP3/OGG format. Example 20_sounds does not work..caught with same error.. Is glad to know anyone can help me out with this..?

jrfoxw commented 7 years ago

Did you try using an MP3 instead of a WAV file? I had a similar problem when using a .wav file, also make sure that the sounds directory is accessible and normally you access a directory using

let thingsToLoad = ["./sounds/music.wav"]

jrfoxw commented 7 years ago

Is the error happening when your loading your assets? Does it work properly without loading any sound files? Are you running this from a server or just directly from an index.html file?

jrfoxw commented 7 years ago

Try this code inside your script and check your console to see if it's showing the files trying to load :)

let log = console.log
let error = console.error

let music

//An array of files you want to load
let assets = [
               "./sounds/music.wav"
             ];

let canvasWidth = 900
let canvasHeight = 900

//Initialize and start Hexi
let g = hexi(canvasWidth, canvasHeight, setup, assets, load);
g.fps = 30;
g.scaleToWindow();
g.start();
g.backgroundColor = "black"

function load(){
    // load assets 
   log(`Loading ${g.loadingFile}`);
   log(`Progress ${g.loadingProgress}`);
   g.loadingBar();
}

function setup(){
   music = g.sound("./sounds/music.wav")
   music.play()

}

function play(){
  // moved music.play() to setup()
}
se7enTale commented 7 years ago

Caught the same error with zero progress.. works fine without sound..

jrfoxw commented 7 years ago

I'm assuming it does the same with any sound file, not just this one. So on that assumption, and looking at the error code it looks like that the file is not getting recognized as a string or array when it xhrOnLoad's. As long as you have full permissions on your system (admin, root) it should work.

If you want you can send me a link to the file your using and I can test it on my end.

kittykatattack commented 7 years ago

@jrfoxw Thanks so much for your help with this!