I am using jPlayer plugin.
In example there are 13 songs in playlist. I want to set a start time (currentTime) for each song like : 1st song starts from 2 sec, 2nd song start from 3 sec and 5th song start from 4 sec.
Here is an example jsFiddle.
In this example I added var tag = $('.audio-tag audio')[0];
to find current playing song globally but it is out of jPlayer plugin.
How to get current audio tag
& number
to set currentTime for each song of jPlayer playlist?
SOLUTION
var $jp = $('#jquery_jplayer_1');
$jp.on($.jPlayer.event.setmedia, function(e){
console.log("Current track", e.jPlayer.status.media);
console.log("Currentr track index", myPlayer.current);
// For first track (0) - 2 sec, second track (1) - 3 sec, etc.
var time = myPlayer.current + 2;
// Jump to desired time
setTimeout(function(){
$jp.jPlayer( "play", time);
}, 100);
});
NOTES
Call setTimeoout
is needed because according to the manual
If issued immediately after a
setMedia
command, with thetime
parameter, and when the browser is using the HTML5 solution, this command will initially fail and an internal timeout is setup to retry the command every 100ms until it succeeds.
DEMO
See this jsFiddle for code and demonstration.