Html MEDIA_ERR_SRC_NOT_SUPPORTED html5 音频问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2260321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MEDIA_ERR_SRC_NOT_SUPPORTED html5 audio woes
提问by jshen
I am working on an html5 audio player and everything is working fine when I server the .ogg file from the same host as the html page. When I put the ogg file in my cdn it fails and the error code is MEDIA_ERR_SRC_NOT_SUPPORTED
我正在开发一个 html5 音频播放器,当我从与 html 页面相同的主机提供 .ogg 文件时,一切正常。当我将 ogg 文件放入我的 CDN 时,它失败了,错误代码是 MEDIA_ERR_SRC_NOT_SUPPORTED
For example, this works fine
例如,这工作正常
<audio src="/song.ogg" id="player">
Your browser does not support the <code>audio</code> element.
</audio>
But this fails with the above error code
但这失败并显示上述错误代码
<audio src="http://mycdn.com/song.ogg" id="player">
Your browser does not support the <code>audio</code> element.
</audio>
The headers for the audio file that fails look something like this (this is from a different ogg file which exhibits the same behavior)
失败的音频文件的标题看起来像这样(这是来自不同的 ogg 文件,它表现出相同的行为)
HTTP/1.1 200 OK
Server: CacheFlyServe v26b
Date: Sat, 13 Feb 2010 21:10:48 GMT
Content-Type: application/octet-stream
Connection: close
ETag: "c6ee7d86e808cc44bbd74a8db94a5aae"
X-CF1: fA.syd1:cf:cacheD.syd1-01
Content-Length: 2398477
Last-Modified: Sat, 13 Feb 2010 20:50:56 GMT
Accept-Ranges: bytes
X-Cache: MISS from deliveryD-syd1
采纳答案by Nickolay
The Content-Type=octet/stream header is the problem, although if I'm reading the spec correctly, it shouldn't be. Here's a testcase: http://mozilla.doslash.org/stuff/video-test/video.html
Content-Type=octet/stream 标头是问题所在,但如果我正确阅读规范,则不应该如此。这是一个测试用例:http: //mozilla.doslash.org/stuff/video-test/video.html
I filed a bugin Mozilla's bugzilla about this. [edit] the response:
我在 Mozilla 的 bugzilla 中提交了一个关于这个的错误。[编辑] 回应:
We don't do any content sniffing to work out what the content is - we rely on the correct mime type being provided. This is why application/octet-stream does not play and way we return "" for canPlayType.
我们不进行任何内容嗅探来确定内容是什么 - 我们依赖于提供的正确 mime 类型。这就是为什么 application/octet-stream 不播放以及我们为 canPlayType 返回 "" 的方式。
回答by user273187
The problem is the mime type you are serving the audio file with. It needs to be 'audio/ogg', 'application/ogg' or 'video/ogg' for Firefox to play it. Firefox doesn't do any form of 'content sniffing' to work out what format the file is in - it relies entirely on the mime type.
问题在于您提供音频文件的 MIME 类型。它需要是“audio/ogg”、“application/ogg”或“video/ogg”,Firefox 才能播放它。Firefox 不会进行任何形式的“内容嗅探”来确定文件的格式——它完全依赖于 mime 类型。