Best way to use playHead method with time instead of percentOfSeekable

882 views
Skip to first unread message

Peter Hanley

unread,
Dec 8, 2011, 4:16:11 PM12/8/11
to jpl...@googlegroups.com
I have a method that fast forwards the audio of a slideshow on a swipe gesture - this works, but pauses the audio (obviously) - I'd like to use the functionality of playHead, but for whatever reason that only accepts percentOfSeekable as an argument instead of a time parameter.  

Is there a way to get the playHead functionality using time as an argument rather than percentOfSeekable?  I had a vague sense from the docs that $("#audioPlayer").jPlayer("playHead", ( slideScript.nextpage[0].id.start / audiolength  )); would be unreliable unless I gave the audiolength as a variable and didn't rely on jPlayer to get that info for me.


$("#" + i).live("swipeleft", function(){

    var nextpage = $(this).next('div[data-role="page"]');   

    // swipe using id of next page if exists
    if (nextpage.length > 0) {
  $.mobile.changePage(nextpage, 'slide');
        $("#audioPlayer").jPlayer( "pause", (eval("slideScript." + nextpage[0].id + ".start"))  );
        // note - slideScript.nextpage[0].id.start would resolve to a time in seconds
//$("#audioPlayer").jPlayer("playHead", (   )));
}
});       


Dustin Blake

unread,
Dec 10, 2011, 8:53:44 AM12/10/11
to jpl...@googlegroups.com
http://jplayer.org/latest/developer-guide/#jPlayer-play

.jPlayer("play", seconds);  moves the play-head position as well

Peter Hanley

unread,
Dec 12, 2011, 11:56:15 AM12/12/11
to jpl...@googlegroups.com
Awesome, I guess I need to upgrade my local copy of jPlayer - thanks!


Peter Hanley

unread,
Dec 12, 2011, 12:09:15 PM12/12/11
to jpl...@googlegroups.com
Oh, wait - I see. Here was the behavior I was trying to get out of playhead:

Whether the media plays from that point depends on its current state. ie., If it was playing, play continues from the new play-head. If it was paused, the media is cued to the new play-head position.

So yeah, I have play and pause with seconds in my script - the problem I've been had since posting is being unclear how to check if the media is playing - I stuck my play statements in an if statement:

if( $.jPlayer.event.playing ) {
  $("#audioPlayer").jPlayer( "pause", (eval("slideScript." + nextpage[0].id + ".start")) );       
    $("#audioPlayer").jPlayer( "play");
  console.log("pause and play");
} else {
    $("#audioPlayer").jPlayer( "play", (eval("slideScript." + nextpage[0].id + ".start")) );
    console.log("pause");
}

But regardless of the state of play (playing or paused) the $.jPlayer.event.playing selects, I'm guessing because the event is declared, but you can't use the event as a check of state (which as I type it makes sense, duh) 

Looking over the docs though, there doesn't seem to be a method for checking if the player is playing or paused - I'm guessing I can just make a variable and bind setting it's value to the play and pause events, but I feel like I'm missing something simple. 

Peter Hanley

unread,
Dec 12, 2011, 12:11:25 PM12/12/11
to jpl...@googlegroups.com
My fault, I think I found it - I need more coffee, I'm usually better than this. 

Peter Hanley

unread,
Dec 13, 2011, 10:11:13 AM12/13/11
to jpl...@googlegroups.com
For completeness, here's the function I wrote to handle the swipe:

function swipePlay(timeIndex){
  if ( $("#audioPlayer").data("jPlayer").status.paused ) {
  $("#audioPlayer").jPlayer( "pause", timeIndex );
    } else {
        $("#audioPlayer").jPlayer( "play", timeIndex );
    }
}

it gets used in the mobile app to handle swipe events which fast forward or rewind to another slide, and the playhead needs to be set to the new queue point:

$("#" + i).live("swipeleft", function(){
  var nextpage = $(this).next('div[data-role="page"]');
  // swipe  to next page using id of next page if exists
    if (nextpage.length > 0) {
  $.mobile.changePage( nextpage, {
                             transition: "slide",
                             reverse: false,
                             changeHash: true
});
// mark page as having been played
        eval("slideScript." +  $(this)[0].id + ".done = true;" );
// move audio playhead to next slide queue point
swipePlay( eval("slideScript." + nextpage[0].id + ".start") ); 
  }
});         

It looks so easy when it's done - thanks for the help!
Reply all
Reply to author
Forward
0 new messages