Javascript 检查jPlayer是否正在播放
可以检查一下现在是否正在播放吗?我每页有几个玩家,我需要根据当前正在玩的jPlayer更改一些类。对我来说,最明显的检查是查看我正在检查的玩家当前是否处于播放状态。我在网上找到了一些关于比赛项目的信息,但不知道如何使用它 目前,我有以下几点,这在我的情况下是有效的,但更好的解决方案是在单击按钮(触发播放功能)时检查哪个播放器正在播放:Javascript 检查jPlayer是否正在播放,javascript,jplayer,Javascript,Jplayer,可以检查一下现在是否正在播放吗?我每页有几个玩家,我需要根据当前正在玩的jPlayer更改一些类。对我来说,最明显的检查是查看我正在检查的玩家当前是否处于播放状态。我在网上找到了一些关于比赛项目的信息,但不知道如何使用它 目前,我有以下几点,这在我的情况下是有效的,但更好的解决方案是在单击按钮(触发播放功能)时检查哪个播放器正在播放: // Shows in what player the song is currently playing. var currentSongId; functi
// Shows in what player the song is currently playing.
var currentSongId;
function play(songId) {
$(".playing").removeClass("playing");
$(".stop").removeClass("stop").addClass("play");
// If some song is playing-stop it and resets current song so that on next play-it starts playing again
if (songId == currentSongId) {
currentSongId = null;
return;
}
// some other logic where I set currentSongId1 or 2, depending on what player's play is fired.
}
游戏事件绑定示例:
$(id).bind($.jPlayer.event.play, function(event) {
if (event.status.currentTime>0 && event.status.paused===false) {
// Its playing right now
}
});
var srcvalue = "";
var songName = "";
function play(songId) {
srcvalue = $(songId).attr('src');
songName = $(songId).attr('title');
// Show the new song's title
$(".jp-title ul li").text(songName);
// Then add the new song
$("#jquery_jplayer_1").jPlayer("setMedia", {
oga: srcvalue
}
// Play from the begining
).jPlayer("playHead", 0).jPlayer("play");
}
$(document).ready(function() {
// Get first song
srcvalue = $(".song:first-child").attr('src');
songName = $(".song:first-child").attr('title');
// Then show the first song's title
$(".jp-title ul li").text(songName);
// Bind click event to playlist
$(".song").each(function() {
$(this).click(function() {
play($(this));
});
});
// Starting value
$("#jquery_jplayer_1").jPlayer({
ready: function(event) {
$(this).jPlayer("setMedia", {
oga: srcvalue
});
},
supplied: "oga"
});
});
还要检查:
带有jPlayer的MP3列表:
$(id).bind($.jPlayer.event.play, function(event) {
if (event.status.currentTime>0 && event.status.paused===false) {
// Its playing right now
}
});
var srcvalue = "";
var songName = "";
function play(songId) {
srcvalue = $(songId).attr('src');
songName = $(songId).attr('title');
// Show the new song's title
$(".jp-title ul li").text(songName);
// Then add the new song
$("#jquery_jplayer_1").jPlayer("setMedia", {
oga: srcvalue
}
// Play from the begining
).jPlayer("playHead", 0).jPlayer("play");
}
$(document).ready(function() {
// Get first song
srcvalue = $(".song:first-child").attr('src');
songName = $(".song:first-child").attr('title');
// Then show the first song's title
$(".jp-title ul li").text(songName);
// Bind click event to playlist
$(".song").each(function() {
$(this).click(function() {
play($(this));
});
});
// Starting value
$("#jquery_jplayer_1").jPlayer({
ready: function(event) {
$(this).jPlayer("setMedia", {
oga: srcvalue
});
},
supplied: "oga"
});
});
小提琴:
多个jPlayer实例:
$(id).bind($.jPlayer.event.play, function(event) {
if (event.status.currentTime>0 && event.status.paused===false) {
// Its playing right now
}
});
var srcvalue = "";
var songName = "";
function play(songId) {
srcvalue = $(songId).attr('src');
songName = $(songId).attr('title');
// Show the new song's title
$(".jp-title ul li").text(songName);
// Then add the new song
$("#jquery_jplayer_1").jPlayer("setMedia", {
oga: srcvalue
}
// Play from the begining
).jPlayer("playHead", 0).jPlayer("play");
}
$(document).ready(function() {
// Get first song
srcvalue = $(".song:first-child").attr('src');
songName = $(".song:first-child").attr('title');
// Then show the first song's title
$(".jp-title ul li").text(songName);
// Bind click event to playlist
$(".song").each(function() {
$(this).click(function() {
play($(this));
});
});
// Starting value
$("#jquery_jplayer_1").jPlayer({
ready: function(event) {
$(this).jPlayer("setMedia", {
oga: srcvalue
});
},
supplied: "oga"
});
});
html:
jQuery:
$(document).ready(function() {
var i = 0;
var srcvalue = "";
var songName = "";
// For each player
$(".player").each(function(){
srcvalue = $(this).attr('src');
songName = $(this).attr('title');
// Add html elements
$(this).after(
'<div id="jp_container_' + i + '" class="jp-audio">' +
'<div class="jp-type-single">' +
'<div class="jp-gui jp-interface">' +
'<ul class="jp-controls">' +
'<li> <a class="jp-play" tabindex="1" href="javascript:;">play</a> </li>' +
'<li> <a class="jp-pause" tabindex="1" href="javascript:;" style="display: none;">pause</a> </li>' +
'<li> <a class="jp-stop" tabindex="1" href="javascript:;">stop</a> </li>' +
'<li> <a class="jp-mute" title="mute" tabindex="1" href="javascript:;">mute</a> </li>' +
'<li> <a class="jp-unmute" title="unmute" tabindex="1" href="javascript:;" style="display: none;">unmute</a> </li>' +
'<li> <a class="jp-volume-max" title="max volume" tabindex="1" href="javascript:;">max volume</a> </li>' +
'</ul>' +
'<div class="jp-progress">' +
'<div class="jp-seek-bar" style="width: 100%;">' +
'<div class="jp-play-bar" style="width: 0%;"> </div>' +
'</div>' +
'</div>' +
'<div class="jp-volume-bar">' +
'<div class="jp-volume-bar-value" style="width: 80%;"></div>' +
'</div>' +
'<div class="jp-time-holder">' +
'<div class="jp-current-time">00:00</div>' +
'<div class="jp-duration">00:00</div>' +
'<ul class="jp-toggles">' +
'<li> <a class="jp-repeat" title="repeat" tabindex="1" href="javascript:;">repeat</a> </li>' +
'<li> <a class="jp-repeat-off" title="repeat off" tabindex="1" href="javascript:;" style="display: none;">repeat off</a> </li>' +
'</ul>' +
'</div>' +
'</div>' +
'<div class="jp-title">' +
'<ul>' +
'<li>' + songName + '</li>' +
'</ul>' +
'</div>' +
'<div class="jp-no-solution" style="display: none;">' +
'<span>Update Required</span> To play the media you will need to either update your browser to a recent version or update your <a target="_blank" href="http://get.adobe.com/flashplayer/">Flash plugin</a>.' +
'</div>' +
'</div>' +
'</div>');
$(this).jPlayer({ // Create player
// The $.jPlayer.event.ready event
ready: function(event) {
// Set media
$(this).jPlayer("setMedia", { oga: srcvalue });
},
/* This is the playing state and if im not mistaken
* you were looking for this.
* playing: function() { },
* pause: function() { },
*/
// On each play disable others
play: function() {
// Pause all except this one
$(this).jPlayer("pauseOthers");
/* This means start from 0
* when used in play even after pause event
* it will start from begining
*/
$(this).jPlayer("playHead", 0);
},
// The $.jPlayer.event.ended event
ended: function() {
// Repeat the media
$(this).jPlayer("playHead", 0);
},
// Supplied MIME types
supplied: "oga",
// Css Ancestor
cssSelectorAncestor: '#jp_container_' + i,
// Css Selector
cssSelector: {
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'
},
// Warning Alerts
warningAlerts: false
});
i = i + 1;
});
});
$(文档).ready(函数(){
var i=0;
var srcvalue=“”;
var songName=“”;
//每名球员
$(“.player”)。每个(函数(){
srcvalue=$(this.attr('src');
songName=$(this.attr('title');
//添加html元素
美元(本)。之后(
'' +
'' +
'' +
“”+
“”+
“”+
“”+
“”+
“”+
“”+
“
”+
'' +
'' +
' ' +
'' +
'' +
'' +
'' +
'' +
'' +
'00:00' +
'00:00' +
“”+
“”+
“”+
“
”+
'' +
'' +
'' +
“”+
“- ”+歌曲名+”
”+
“
”+
'' +
'' +
“播放媒体需要更新您需要将浏览器更新为最新版本或更新您的浏览器。”+
'' +
'' +
'');
$(this).jPlayer({//Create player
//$.jPlayer.event.ready事件
就绪:功能(事件){
//设置媒体
$(this.jPlayer(“setMedia”,{oga:srcvalue});
},
/*这是比赛状态,如果我没弄错的话
*你在找这个。
*播放:函数(){},
*暂停:函数(){},
*/
//在每场比赛中,禁止其他人
播放:函数(){
//除此之外,暂停所有操作
$(this.jPlayer(“pauseOthers”);
/*这意味着从0开始
*在播放中使用时,即使在暂停事件之后
*它将从头开始
*/
$(this.jPlayer(“playHead”,0);
},
//$.jPlayer.event.ended事件
完:函数(){
//重复媒体
$(this.jPlayer(“playHead”,0);
},
//提供的MIME类型
提供:“oga”,
//Css祖先
CSS选择器存储:“#jp_容器”+i,
//Css选择器
CSS选择器:{
视频播放:“.jp视频播放”,
播放:“.jp播放”,
暂停:'.jp暂停',
停止:'.jp停止',
seekBar:“.jp搜索栏”,
playBar:“.jp playBar”,
静音:'.jp静音',
取消静音:'.jp取消静音',
卷栏:'.jp卷栏',
volumeBarValue:“.jp卷栏值”,
卷最大:'.jp卷最大',
currentTime:“.jp当前时间”,
持续时间:'.jp持续时间',
全屏:'.jp全屏',
restoreScreen:“.jp还原屏幕”,
重复:'.jp重复',
repeatOff:“.jp repeat off”,
gui:“.jp gui”,
无解决方案:'.jp无解决方案'
},
//警告警报
警告:错
});
i=i+1;
});
});
小提琴:或者您可以使用:
if($("#priPlayerID").jPlayer("getData","diag.isPlaying") == true){
//Is Playing
}
简单一点:
if($("#jquery_jplayer_1").data().jPlayer.status.paused == false){
//Is Playing;
}
嗯,不完全是..我需要检查一些按钮单击player1是否正在播放-将类更改为'smth'否则-更改为'smth1'。而不是它的
(event.jPlayer.status.duration>0)
和(event.jPlayer.status.paused==false)
你应该检查。是的,似乎就是它。。以及如何获取事件.jPlayer.status.duration
<代码>$(“#myjplayer”).event.jPlayer.status.duration返回错误..我添加了一些代码。谢谢你的回复,请看看我到底需要什么。。我想我们彼此误解了。在$.jPlayer.event.play
事件处理程序中,event.status.paused
befalse
什么时候会出现?对于1.0.0以上的版本,它不起作用(没有答案)