用HTML5和jQuery實作出來的播放器
可以改善對於嵌入影音在網頁上,都會被播放軟體限制住的問題
另外網路上也有人會開發樣版,例如 Midnight-Black
由於官網並沒有很明顯的文件說明HTML要怎麼寫,因此附上自己使用的HTML
<div id="player"> <div id="jquery_jplayer_1" class="jp-jplayer"></div> <div id="jp_container_1" class="jp-audio"> <div class="jp-type-single"> <div class="jp-gui jp-interface"> <ul class="jp-controls"> <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li> <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li> <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li> <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li> <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li> <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li> </ul> <div class="jp-progress"> <div class="jp-seek-bar"> <div class="jp-play-bar"></div> </div> </div> <div class="jp-volume-bar"> <div class="jp-volume-bar-value"></div> </div> <div class="jp-time-holder"> <div class="jp-current-time"></div> <div class="jp-duration"></div> <ul class="jp-toggles"> <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li> <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li> </ul> </div> </div> <div class="jp-title"> <ul> <li>Listen</li> </ul> </div> <div class="jp-no-solution"> <span>Update Required</span> To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>. </div> </div> </div> </div><!--end #player-->
jPlayer基本使用
$("#jquery_jplayer_1").jPlayer({ ready: function (event) { $(this).jPlayer("setMedia", { //也可用title參數取代jp-title的值 //title: "Bubble", m4a: "http://jplayer.org/audio/m4a/Miaow-07-Bubble.m4a", oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg" }); }, swfPath: "js", supplied: "m4a, oga", wmode: "window", //Duration 倒數會正數(true為倒數) remainingDuration: true, });
動態切換歌曲
var player = $("#jquery_jplayer_1"); player.jPlayer({ error: function (e) { console.log(e.jPlayer.error); alert(e.jPlayer.error.message); }, swfPath: "js", supplied: "m4a, oga", }); player.jPlayer("setMedia", { m4a: "http://jplayer.org/audio/m4a/Miaow-07-Bubble.m4a", oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg" }); //重頭播放 player.jPlayer("play", 0);