javascript jPlayer - 如何确定它是否正在播放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9153788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:46:13  来源:igfitidea点击:

jPlayer - how to find out if it's playing

javascriptjqueryjplayer

提问by simPod

How can I find out if jPlayer is playing? I tried this alert($.jPlayer.event.playing);but it doesn't work.

我如何知道 jPlayer 是否正在播放?我试过这个,alert($.jPlayer.event.playing);但它不起作用。

采纳答案by Lloyd

Kyle's method works fine, here's a fiddle to demonstrate it in action: http://jsfiddle.net/75lb/95EPu/

凯尔的方法工作正常,这里有一个小提琴来演示它的实际效果:http: //jsfiddle.net/75lb/95EPu/

However, ordinarily you wouldn't need to access jPlayer's internals like this, being an event-driven plugin.. would it be cleaner to respond to one of jPlayer's many events (at the appropriate moment)? http://www.jplayer.org/latest/developer-guide/#jPlayer-events

然而,通常你不需要像这样访问 jPlayer 的内部,作为一个事件驱动的插件..响应 jPlayer 的许多事件之一(在适当的时候)会更干净吗? http://www.jplayer.org/latest/developer-guide/#jPlayer-events

回答by Kyle Macey

I've not worked with Jplayer specifically, but playing around, this returned false if the media was playing and true if it wasn't.

我没有专门与 Jplayer 合作过,但是在玩弄时,如果媒体正在播放,则返回 false,否则返回 true。

$('#jquery_jplayer_1').data().jPlayer.status.paused

回答by Patrick Farrell

On my setup, I noticed the class "jp-state-playing" was added to the div that included jp-audio. I have not done a lot of research, but querying for a null object or not seemed better than tying myself to jPlayers internals.

在我的设置中,我注意到类“jp-state-playing”被添加到包含 jp-audio 的 div 中。我没有做过很多研究,但查询是否为空对象似乎比将自己绑定到 jPlayers 内部更好。

回答by btaylor507

var duration = $('#jquery_jplayer_1').data("jPlayer").status.currentTime;

if(duration){
  // Source is loaded and playing 
}