如何为 html5 音频标签实现 Flash 回退?例如我有这个音频标签
<div class = "div.jp-audio"><audio class ="audio-player" name= "audio-player" src="song.mp3" ></audio></div>
由于并非所有浏览器都支持 .mp3 文件,如何启用或创建 Flash 回退
这是一个很好的代码片段,它有一个很好地实现的 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
希望能帮助到你!
在 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"); }