简体   繁体   English

浏览器无法处理JS调用的mp3资源,而是将其下载(DOMException:无法解码音频数据)

[英]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 我正在尝试在服务器上安装html5 / js游戏,游戏中有几个mp3文件会在js代码中加载...类似

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 它正在使用createjs加载文件,但问题与createjs无关,因为我一直在尝试使用纯JavaScript代码加载音频文件时遇到相同的问题

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 ! 所以这是问题所在,本地主机中的此代码工作正常,但是当我将其上载到服务器而不是加载mp3文件时,chrome将下载文件! 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 即时通讯不知道是什么问题,但是即使我直接在浏览器中输入mp​​3文件,它也会下载而不是播放/流式播放

The problem is going to be the MIME type of your file handler. 问题将是文件处理程序的MIME类型。 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. 如果指定正确的mime类型并正确下载,浏览器将在用户指定的应用程序中打开MP3文件,以处理该.mp3文件类型。

The CONTENT DISPOSITION http header field is key here for you: CONTENT DISPOSITION http标头字段是您的关键:

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

Please show us some code so we can help further. 请向我们展示一些代码,以便我们提供进一步的帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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