jquery.jplayer使用

1、首先是3个包导入
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/jPlayer/js/jquery.jplayer.min.js"></script>
<link href="<%=request.getContextPath()%>/jPlayer/skin/blue.monday/jplayer.blue.monday.css" rel="stylesheet" type="text/css" />


注:下面两个是在官网中下载demo中自带的 http://www.jplayer.org/

2、在网页<body>中添加层
<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>
	</div>




3、然后是加载插件
$(function ()
    {
		$("#jquery_jplayer_1").jPlayer({
			ready: function () {
				$(this).jPlayer("setMedia", {
					//mp3:"http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3"
				});
			},
			swfPath: "js",
			supplied: "mp3"
		});
    });







下面是一些属性介绍:
supplied: "mp3"   表示支持的文件类型,例如:"m4a, oga"等
swfPath: "js"   路径相关,可以不管
$(this).jPlayer("setMedia",{})  设置播放文件地址

想自己点击莫个按钮,然后把语音文件地址传过来,然后播放指定的语音文件,可以这样
$("#jquery_jplayer_1").jPlayer("setMedia", {
   mp3:url
}).jPlayer("play");

其中jquery_jplayer_1为<body>标签中用于显示该控件的层的ID,url为传过来的语音文件地址,.jPlayer("play");达到自动播放

你可能感兴趣的:(jquery,jPlayer)