Search code examples
audiohtml5-audiojplayer

Make jPlayer stay at end of track


As demonstrated in the standard jPlayer demo, when the track ends, the player resets time to zero. Is there any way to make it stay at the end of the track?


Solution

  • Use the ended() event in conjunction with the playHead method to keep the play head at the end when it ends.

    Modifying the example, here's what I got:

    $(document).ready(function() {
    
        $("#jquery_jplayer_1").jPlayer({
            ready: function(event) {
                $(this).jPlayer("setMedia", {
                    mp3: "http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3",
                    oga: "http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
                });
            },
            swfPath: "http://www.jplayer.org/2.1.0/js",
            supplied: "mp3, oga",
            ended : function(){
                console.log("ended");
                $(this).jPlayer("playHead",100);
            }
        });
    });                                      
    ​
    

    JSFiddle: http://jsfiddle.net/wjsKa/2/
    Reference: http://jplayer.org/latest/developer-guide/