简体   繁体   中英

browser cant process mp3 resources called by JS , instead it will download them (DOMException: Unable to decode audio data)

i'm trying to install a html5/js game on my server there are couple of mp3 files in the game which would load up in the js code ... something like

createjs.Sound.alternateExtensions = ["ogg"];
createjs.Sound.addEventListener("fileload", createjs.proxy(this.soundLoaded, this));
createjs.Sound.registerSound(REL_GAME_URL + "sounds/chip.mp3", "chip");
createjs.Sound.registerSound(REL_GAME_URL + "sounds/click.mp3", "click");
createjs.Sound.registerSound(REL_GAME_URL + "sounds/fiche_collect.mp3", "fiche_collect");
createjs.Sound.registerSound(REL_GAME_URL + "sounds/fiche_select.mp3", "fiche_select");
createjs.Sound.registerSound(REL_GAME_URL + "sounds/wheel_sound.mp3", "wheel_sound");

its is using createjs to load up the files but the problem has nothing to do with createjs as i've been having the same problem with pure javascript codes trying to load up audio files

so here is the problem , this codes in the localhost works fine but when i upload it on the server instead of loading the mp3 files chrome would download the files ! and gives me this error in the console :

Uncaught (in promise) DOMException: Unable to decode audio data

im not sure what the problem is , but even when i enter mp3 file directly in the browser it will download it instead of play/stream it

The problem is going to be the MIME type of your file handler. This is what tells the browser how to tell the OS how to handle it. If you specify the correct mime type, and do the download correctly, the browser will open the MP3 file in the application the user has specified to handle that .mp3 file type.

The CONTENT DISPOSITION http header field is key here for you:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Please show us some code so we can help further.

因此,这是将来可能会遇到此问题的人的答案...这是与Internet下载管理器(IDM)的集成问题...我已通过禁用idm解决了它!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM