
这个是我选择使用它的首要原因。
现在从需求上来了解它的使用方法吧。第一个需求:MP3格式的音频在网页播放,样式如下:

刚看到这个需求的时候,还是觉着有些难度的。我从官网(http://www.jplayer.cn/)上下载了这个的压缩包,直接拿出了里面的例子套用(路径:/examples/blue.monday/demo-01-supplied-mp3.htm),不得不说,这也是学会使用这个插件的最快的方法。压缩包里面的例子很全面,总有一款适合你。
demo的样式是这样的:

现在看一下它的html结构:
<div id="jquery_jplayer_1" class="jp-jplayer"></div><!--存放音频和视频源,绝对需要--><div id="jp_container_1" class="jp-audio" role="application" aria-label="media player"><!--播放器样式wrap--><div class="jp-type-single"><div class="jp-gui jp-interface"><div class="jp-controls"><!--播放和停止按钮--><button class="jp-play" role="button" tabindex="0">play</button><button class="jp-stop" role="button" tabindex="0">stop</button></div><div class="jp-progress"><!--进度条--><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div class="jp-volume-controls"><!--音量控制键--><button class="jp-mute" role="button" tabindex="0">mute</button><button class="jp-volume-max" role="button" tabindex="0">max volume</button><div class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div></div><div class="jp-time-holder"><!--视频时间和重复播放按钮--><div class="jp-current-time" role="timer" aria-label="time"> </div><div class="jp-duration" role="timer" aria-label="duration"> </div><div class="jp-toggles"><button class="jp-repeat" role="button" tabindex="0">repeat</button></div></div></div><div class="jp-details"><!--视频的主题--><div class="jp-title" aria-label="title"> </div></div><div class="jp-no-solution"><!--jplayer提示信息,默认隐藏--><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>结构是不是很清晰呢,我们需要的所有功能这里面都已经包含了,根据我的需求,我可以只保留播放和暂停按钮以及进度条,简化过后的html:
<div id="jquery_jplayer_1" class="jp-jplayer"></div><!--存放音频和视频源,绝对需要--><div id="jp_container_1" class="jp-audio" role="application" aria-label="media player"><!--播放器样式wrap--><div class="jp-type-single"><div class="jp-gui jp-interface"><div class="jp-controls"><!--播放暂停按钮--><button class="jp-play" role="button" tabindex="0">play</button></div><div class="jp-progress"><!--进度条--><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div></div></div></div>
<script type="text/javascript">//<![CDATA[$(document).ready(function(){$("#jquery_jplayer_1").jPlayer({ready: function () {$(this).jPlayer("setMedia", {title: "Bubble",mp3: "http://jplayer.org/audio/mp3/Miaow-07-Bubble.mp3"});},swfPath: "../../dist/jplayer",supplied: "mp3",wmode: "window",useStateClassSkin: true,autoBlur: false,smoothPlayBar: true,keyEnabled: true,remainingDuration: true,toggleDuration: true});});//]]></script>第一个参数:ready$(this).jPlayer("setMedia", {autoPlay: true}).jPlayer("play");自动播放就实现了,页面需求升级,需要媒体循环自动播放,如何实现?在API提供了这样一个事件:ended: function () {$(this).jPlayer("play");},需求继续升级,媒体自动播放1秒后停止,如何实现呢?$(this).jPlayer("setMedia", {}).jPlayer("pause", 1);这样还不够,一个页面同时有多个媒体(这个不细说,压缩包里面有案例),怎么阻止同时播放?play: function() { // 当前媒体播放时,其他媒体暂停播放 $(this).jPlayer("pauseOthers");},......需求变化很多,但万变不离其中,有觉得实现不了的功能,可以多多看下官网的API,maybe你就找到了解决之道。