jPlayer使⽤详解(转)【A】最简单的:(不⽤⽪肤,单⼀⾸歌)
◆头:
<script src="css_js/jquery.js"></script>
<script src="jPlayer/jquery.jplayer.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
mp3: "media/mysound.mp3", m4a: "media/mysound.mp4", oga: "" });
},
swfPath: "jPlayer",
supplied: "mp3, m4a, oga"
});
});
</script>
◆◆注:如果要⾃动播放和⾃动循环,要加上.jPlayer("play")和.jPlayer("repeat")在这⾥:$(this).jPlayer("setMedia", {
mp3: "media/mysound.mp3", m4a: "media/mysound.mp4", oga: "" }).jPlayer("play").jPlayer("repeat");
◆⾝体:
<div id="jquery_jplayer_1"></div><!--播放⾳频的flash隐藏窗⼝-->
<div id="jp_container_1">
<a href="#" class="jp-play">Play</a>
<a href="#" class="jp-pause">Pause</a>
javascript说明</div>
======================
【B】全功能界⾯:
◆头同上,再加上:
<link rel="stylesheet" type="text/css" href="jPlayer/pink.flag/jplayer.pink.flag.css">
======================
【C】多⾸歌列表播放:
◆头,必须再导⼊个jplayer.playlist.min.js⽂件才能播放列表:
<script src="css_js/jquery.js"></script>
<script src="jPlayer/jquery.jplayer.min.js"></script>
<script src="jPlayer/add-on/jplayer.playlist.min.js"></script>
<link rel="stylesheet" type="text/css" href="jPlayer/pink.flag/jplayer.pink.flag.css">
<script type="text/javascript">
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
{title:"My Sound 1",mp3: "media/mysound1.mp3", oga:""},
{title:"My Sound 2",mp3: "media/mysound2.mp3", oga:"", free:true},//free:true会在列表中此条⾳乐名称右边出现格式选择
{title:"My Sound 3",mp3: "media/mysound3.mp3", oga:""}
], {
swfPath: "../js",
supplied: "oga, mp3",
wmode: "window",
smoothPlayBar: true,
keyEnabled: true
});
});
</script>
◆◆如果要⾃动播放且⾃动循环要加上ready: function (){$(this).jPlayer("play").jPlayer("repeat");},在这⾥:
……
{title:"My Sound 2",mp3: "media/mysound2.mp3", oga:""},
{title:"My Sound 3",mp3: "media/mysound3.mp3", oga:""}
], {
ready: function (){$(this).jPlayer("play").jPlayer("repeat");},
swfPath: "../js",
……
◆⾝体其他部分不变同上,在.jp-toggles⾥加上了随机播放的开关,在.jp-interface后⾯加了个播放列表的空容器:
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio">
<div class="jp-type-playlist">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li><a href="javascript:;" class="jp-previous" tabindex="1">previous</a></li>
<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-next" tabindex="1">next</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-current-time"></div>
<div class="jp-duration"></div>
<ul class="jp-toggles">
<li><a href="javascript:;" class="jp-shuffle" tabindex="1" title="shuffle">shuffle</a></li>
<li><a href="javascript:;" class="jp-shuffle-off" tabindex="1" title="shuffle off">shuffle off</a></li>
<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 class="jp-playlist"><ul><li></li></ul></div>
</div>
</div>
======================
【D】更复杂的JS设置及说明:
◆头:
<script type="text/javascript">
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () { //当flash⼀切载⼊就绪后,发⽣的事,如⾃动播放
$(this).jPlayer("setMedia", {
mp3: "media/mysound.mp3", m4a: "media/mysound.mp4", oga: "" });
},
swfPath: "jPlayer", //播放⽤flash所在的相对路径
solution: 'html, flash',
supplied: "mp3, m4a, oga",
preload: 'metadata',
volume: 0.8, //默认打开时⾳量
muted: false,
backgroundColor: '#000000',
cssSelectorAncestor: '#jp_container_1',
wmode: "window",
smoothPlayBar: true,
keyEnabled: true, //键盘快捷键(上下左右空⽩)可⽤否
cssSelector: { //可以⽤⾃⼰容器的类名或ID来取代默认
videoPlay: '.jp-video-play',
play: '.jp-play',
pause: '.jp-pause',
stop: '.jp-stop',
seekBar: '.jp-seek-bar',
playBar: '.jp-play-bar',
mute: '.jp-mute',
unmute: '.jp-unmute',
volumeBar: '.jp-volume-bar',
volumeBarValue: '.jp-volume-bar-value',
volumeMax: '.jp-volume-max',
currentTime: '.jp-current-time',
duration: '.jp-duration',
fullScreen: '.jp-full-screen',
restoreScreen: '.jp-restore-screen',
repeat: '.jp-repeat',
repeatOff: '.jp-repeat-off',
gui: '.jp-gui',
noSolution: '.jp-no-solution'
},
errorAlerts: false, //报错开关
warningAlerts: false //报错开关
});
});
</script>
======================
【E】在线流⾳乐播放:
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
ready = true;
$(this).jPlayer("setMedia", stream);
},
pause: function() {
$(this).jPlayer("clearMedia");
},
error: function(event) {
if(ready && type === $.URL_NOT_SET) {
// Setup the media stream again and play it.
$(this).jPlayer("setMedia", stream).jPlayer("play");
}
},
swfPath: "jPlayer",
supplied: "mp3",
preload: "none",
wmode: "window"
});
});
</script>
====================== 视频调⽤⽅法 =======================
======================
【F】单个视频播放:
◆头:
<script src="css_js/jquery.js"></script>
<script src="jPlayer/jquery.jplayer.min.js"></script>
<link rel="stylesheet" type="text/css" href="jPlayer/pink.flag/jplayer.pink.flag.css">
<script type="text/javascript">
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
m4v: "media/myVideo.m4v", ogv: "v", webmv: "media/myVideo.webm", poster: "media/myVideo.png" //封⾯图
}); //如果要⼀开始就全屏,加.jPlayer("fullScreen")但只是全窗⼝⽽不是全屏
},
swfPath: "jPlayer",
supplied: "webmv, ogv, m4v",
size: {
width: "640px", height: "360px", cssClass: "jp-video-360p"
},
smoothPlayBar: true
});
});
</script>
======================
【H】视频列表播放:
◆头,别忘了导⼊jplayer.playlist.min.js才能⽤:
<script src="css_js/jquery.js"></script>
<script src="jPlayer/jquery.jplayer.min.js"></script>
<script src="jPlayer/add-on/jplayer.playlist.min.js"></script>
<link rel="stylesheet" type="text/css" href="jPlayer/pink.flag/jplayer.pink.flag.css">
<script type="text/javascript">
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
{
title:"My Video 1", artist:"me", free:true, //free:true会在列表中此条视频名称右边出现格式选择 m4v: "media/myVideo1.m4v", ogv: "v", poster:"media/myVideo1.png" },
{
title:"My Video 2", artist:"me",
m4v: "media/myVideo2.m4v", ogv: "v", poster:"media/myVideo2.png" }, {
title:"My Video 3", artist:"me",
m4v: "media/myVideo3.m4v", ogv: "v", poster:"media/myVideo3.png" }
], {
swfPath: "jPlayer",
supplied: "ogv, m4v",
size: {width: "640px", height: "360px"},
smoothPlayBar: true
});
});
</script>
======================
【I】给视频加⽂字的popcorn插件:(⽀持中⽂,但貌似字体,颜⾊,位置等都不能改)
◆头,加上popcorn⽂件夹⾥的4个JS⽂件!注意顺序:
<script src="css_js/jquery.js"></script>
<script src="jPlayer/jquery.jplayer.min.js"></script>
<script src="jPlayer/popcorn/popcorn.js"></script>
<script src="jPlayer/popcorn/popcorn.player.js"></script>
<script src="jPlayer/popcorn/popcorn.jplayer.js"></script>
<script src="jPlayer/popcorn/popcorn.subtitle.js"></script>
<link rel="stylesheet" type="text/css" href="jPlayer/pink.flag/jplayer.pink.flag.css">
<script type="text/javascript">
$(document).ready(function(){
var p = Popcorn.jplayer('#jquery_jplayer_1', {
media: {
m4v: "media/myVideo.m4v", ogv: "v", poster:"media/myVideo.png"
},
options: {
swfPath: "jPlayer",
supplied: "ogv, m4v",
size: {width: "640px",height: "360px"},
smoothPlayBar: true}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论