如何为html5音频标签实现闪回后备?例如,我有这个音频标签
<div class = "div.jp-audio"><audio class ="audio-player" name= "audio-player" src="song.mp3" ></audio></div>
如何启用或创建闪回功能,因为并非所有浏览器都支持.mp3文件
答案 0 :(得分:8)
这是一个很好的代码片段,它有一个很好实现的Flash回调:
<audio id="audioplayer" preload controls loop style="width:424px;">
<source src="audio.mp3">
<source src="audio.caf">
</audio>
<script type="text/javascript">
var audioTag = document.createElement('audio');
if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) {
AudioPlayer.embed("audioplayer", {soundFile: "audio.mp3"});
}
</script>
以下是我发现它的参考: Getting HTML5 Audio Tag and Flash Fallback to Work Nicely With All Browsers
希望它有帮助!
答案 1 :(得分:1)
以下是live example使用swfobject&amp; JS。
在HTML中:
<div id="ytplayer"></div>
在JS中:
var audioSupport = document.createElement('audio').canPlayType;
var swfPath = "http://www.youtube.com/v/XSGBVzeBUbk?enablejsapi=1&playerapiid=ytplayer&version=3";
var divID = "ytplayer";
if(audioSupport) { $("#ytplayer").append("Your Browser Supports audio"); }
else { swfobject.embedSWF(swfPath, divID, "425", "356", "8"); }