javascript - Play song at specific time position from a playlist -
i using jplayer plugin.
in example there 13 songs in playlist. want set start time (currenttime) each song : 1st song starts 2 sec, 2nd song start 3 sec , 5th song start 4 sec.
here example jsfiddle.
in example added var tag = $('.audio-tag audio')[0];
find current playing song globally out of jplayer plugin.
how current audio tag
& number
set currenttime 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); // first track (0) - 2 sec, second track (1) - 3 sec, etc. var time = myplayer.current + 2; // jump desired time settimeout(function(){ $jp.jplayer( "play", time); }, 100); });
notes
call settimeoout
needed because according manual
if issued after
setmedia
command,time
parameter, , when browser using html5 solution, command fail , internal timeout setup retry command every 100ms until succeeds.
demo
see this jsfiddle code , demonstration.
Comments
Post a Comment