How can I find out if jPlayer is playing?
I tried this alert($.jPlayer.event.playing);
but it doesn't work.
Asked
Active
Viewed 1.1k times
7

simPod
- 11,498
- 17
- 86
- 139
-
2Hi.. same questions apply here - which browser, media, solution, constructor options? – Lloyd Feb 06 '12 at 09:41
4 Answers
16
I've not worked with Jplayer specifically, but playing around, this returned false if the media was playing and true if it wasn't.
$('#jquery_jplayer_1').data().jPlayer.status.paused

Kyle Macey
- 8,074
- 2
- 38
- 78
-
that's weird :/ it gives me `("#jquery_jplayer").data().jPlayer.status is undefined`. There must be something wrong with my player. In some other cases it returns `$.jPlayer.event is undefined`... – simPod Feb 05 '12 at 23:39
-
I'm sure the missing '$' in your comment was an accident, just make sure you're pointing that to the ID of the DIV you're targeting jPlayer at – Kyle Macey Feb 06 '12 at 00:30
-
Looking at this and your other question, I'm starting to think that you have the wrong selector – Kyle Macey Feb 06 '12 at 00:32
-
it was an accident, it's like `alert($('#jquery_jplayer').data().jPlayer.status.paused);`. I don't think it's wrong selector, I created jPlayer like this `$("#jquery_jplayer").jPlayer({...})`. It's the same selector... That's rly weird – simPod Feb 06 '12 at 01:35
-
Then you're calling `alert($('#jquery_jplayer').data().jPlayer.status.paused);` AFTER the jPlayer is initiated, right? – Kyle Macey Feb 06 '12 at 02:31
-
-
@Kyle Macey yea, I'm calling it in onClick event, it's already initialized there... – simPod Feb 06 '12 at 09:54
6
Kyle's method works fine, here's a fiddle to demonstrate it in action: 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

Lloyd
- 8,204
- 2
- 38
- 53
-
I copied whole code from the result from JSFiddle but it doesn't work in my separate file http://dev.podlipsky.net/ (some css are missing but it doesn't matter). I don't understand why because the code is same and paths are absolute – simPod Feb 06 '12 at 10:32
-
1
-
I'm getting 'true' no matter what. Even when I use `$('#player').jPlayer("play").data().jPlayer.status.paused`. Any help? – Primus202 May 30 '13 at 16:29
0
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.

Patrick Farrell
- 428
- 3
- 12
-
Unfortunately, the container's `.jp-state-playing` class is removed when the player is paused. – Eric Mar 14 '16 at 09:26
0
var duration = $('#jquery_jplayer_1').data("jPlayer").status.currentTime;
if(duration){
// Source is loaded and playing
}

btaylor507
- 211
- 1
- 13
-
Hi there, code-only answers often get flagged for moderation. Why does this work? Please add a little explanation. Cheers! – stef Jun 06 '17 at 18:51