利用JS怎么获取JW player播放停止或者是当前播放时间
宇文峰
2023-12-01
利用
JS如何
获取
JW player
播放停止或者
是
当前播放时间
http://club.itqun.net/showtopic-268025.html
<div id="myPlayer"></div>
<script type="text/javascript">
function playPause() //暂停
{
JW.sendEvent('PLAY', 'false');
}
function startPlay() //开始
播放
{
JW.sendEvent('play');
}
function stopPlay() //
停止播放
{
JW.sendEvent('stop');
}
function changeVolume() //改变音量
{
JW.sendEvent('volume',80)
}
function playMute() //静音
{
JW.sendEvent("mute","true");
}
var s0 = new SWFObject('player.swf','JW','520','300','7');
s0.addParam('allowfullscreen','true');
s0.addParam('allowscriptaccess','always');
s0.addParam('wmode','opaque');
s0.addVariable("enablejs","true");//能不能允许javascript脚本控制flash
s0.addVariable('duration','34');
s0.addVariable('file','03.flv');
s0.addVariable('image','xs.jpg');
s0.addVariable("displayheight","300");//
播放
区域高度
s0.addVariable('backcolor','0x000000');
s0.addVariable('frontcolor','0xffffff');
s0.addVariable('lightcolor','0xff0000');
s0.addVariable('screencolor','0x000000');
s0.addVariable('playlistsize','200');
s0.addVariable('playlist','right');
s0.addVariable('volume','80');
s0.write("myPlayer");//将
播放
器写入到myPlayer层显示
</script>
利用
JS
获取
JWplayer
播放
状态
JScript code
<script type="text/javascript">
// some variables to save
var currentPosition;//
当前播放
秒数
var currentVolume;//
当前
音量
var currentItem;//
当前播放
项
// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("player_id").sendEvent(typ,prm); };
//case "playpause": 暂停
//"prev": "next":"stop": 上一项 下一项
停止
//scrub":秒数"volume":音量 playitem
播放
项"getlink": "fullscreen": "complete": "captions":标题 "audio":
function getUpdate(typ,pr1,pr2,pid) {
if(typ == "time") { currentPosition = pr1; }
else if(typ == "volume") { currentVolume = pr1; }
else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
var id = document.getElementById(typ);
id.innerHTML = typ+ ": "+Math.round(pr1);
pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
if(pid != "null") {
document.getElementById("pid").innerHTML = "(来自
播放
器 <i>"+pid+"</i>的消息)";
}
};
// These functions are caught by the feeder object of the player. RSS专用
function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
function getItemData(idx) {
var obj = thisMovie("player_id").itemData(idx);
var nodes = "";
for(var i in obj) {
nodes += "<li>"+i+": "+obj[i]+"</li>";
}
document.getElementById("data").innerHTML = nodes;
};
// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
};
</script>