Html HTML5 音频在 Firefox 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8831625/
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
HTML5 audio not working on Firefox
提问by Tony
Works fine on Chrome. Moreover, I'm using an ogg file so that's not the problem. I'm running on the latest version 9.0.1. HTML5 audio is supposed to be supported by both Chrome and Firefox.
在 Chrome 上运行良好。此外,我使用的是 ogg 文件,所以这不是问题。我在最新版本 9.0.1 上运行。Chrome 和 Firefox 都应该支持 HTML5 音频。
<audio id="audio">
<source src="audio/Your_Hand_In_Mine.ogg" type="audio/ogg" />
<source src="audio/Your_Hand_In_Mine.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
采纳答案by Tony
The solution is to properly convert the ogg file into mp3 or vice versa. The encoding was wrong when I just renamed the .ogg file to mp3, silly me. I used software called "Audacity" and "Switch" to accomplish this.
解决方案是将 ogg 文件正确转换为 mp3,反之亦然。当我刚刚将 .ogg 文件重命名为 mp3 时,编码是错误的,我很傻。我使用名为“Audacity”和“Switch”的软件来完成此操作。
回答by Brian Hadaway
Most servers (including those used by GoDaddy) by default don't serve the appropriate MIME Types for OGG files. That being the case, you'll need set the appropriate MIME Types for OGG files if you want HTML5 audio players to work correctly in Firefox. So for an Apache server, you would need to add the following to your .htaccess file:
默认情况下,大多数服务器(包括 GoDaddy 使用的服务器)不为 OGG 文件提供适当的 MIME 类型。在这种情况下,如果您希望 HTML5 音频播放器在 Firefox 中正常工作,您需要为 OGG 文件设置适当的 MIME 类型。因此,对于 Apache 服务器,您需要将以下内容添加到 .htaccess 文件中:
AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
Evidently, other browsers will guess the MIME Type based on file extension if a MIME Type isn't served.
显然,如果未提供 MIME 类型,其他浏览器将根据文件扩展名猜测 MIME 类型。
If you want more info about this, check this page on the Mozilla Developer Network: https://developer.mozilla.org/en/Configuring_servers_for_Ogg_media
如果您想了解更多信息,请查看 Mozilla 开发人员网络上的此页面:https: //developer.mozilla.org/en/Configuring_servers_for_Ogg_media
回答by ferensick
http://support.mozilla.org/en-US/questions/758978I found this useful in my case, since I had the proper mime types and still no luck:
http://support.mozilla.org/en-US/questions/758978我发现这对我来说很有用,因为我有正确的 mime 类型但仍然没有运气:
You can't play MP3 files with such a code in Firefox. See https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
您无法在 Firefox 中播放带有此类代码的 MP3 文件。请参阅https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
<audio controls="controls">
<source src="http://www.kevinroseworld.com/Music/OkaVanga/OkaVanga/BajeLaCalle.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
You will have to use a normal object element to play that song in Firefox. You can look these as an example:
您必须使用普通对象元素才能在 Firefox 中播放该歌曲。您可以将这些视为示例:
<object data="music.mp3" type="application/x-mplayer2" width="xxx" height="xxx"><param name="filename" value="music.mp3"></object>
<embed type="application/x-mplayer2" src="file.mp3" height="xxx" width="xxx" >
回答by Raathigesh
try using some Audio libraries to deal with HTML5 audios. Because libraries handle various problems regarding html5 audios. Some libraries provide automatic fallback for flash audio if the browser is not supporting HTML5 audio. One of the best library out there is http://www.schillmania.com/projects/soundmanager2/
尝试使用一些音频库来处理 HTML5 音频。因为库处理有关 html5 音频的各种问题。如果浏览器不支持 HTML5 音频,一些库会为 Flash 音频提供自动回退。最好的图书馆之一是http://www.schillmania.com/projects/soundmanager2/