开发者

jplayer play between certain percents of time in jquery

开发者 https://www.devze.com 2023-02-02 18:28 出处:网络
I know I can start jPlayer at a given point in time or by percent by doing: $(\"#jquery_jplayer\").jPlayer(\"playHead\", 30);

I know I can start jPlayer at a given point in time or by percent by doing:

$("#jquery_jplayer").jPlayer("playHead", 30);

This is when issuing the play command (works fine), but how c开发者_StackOverflow中文版an I constrain the play time between two fixed points, either by absolute time or percent is fine? Ie I want it to start at 30% and end at 50%, etc. Basically just a good snippet of a song. Any ideas or pointers?

http://www.happyworm.com/jquery/jplayer/latest/developer-guide.htm#jPlayer-playHead


Well in jPlayer 1.2 (not newest) you should have an "onProgressChange" event (used for updating the playedTime text), so if you had a global (gasp) var like

var demoSong = true;

Then you could make your onProgressChange function look like this

$("#jquery_jplayer").jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
  jpPlayTime.text($.jPlayer.convertTime(playedTime));
  jpTotalTime.text($.jPlayer.convertTime(totalTime));
  if(demoSong) {
    if(playedPercentAbsolute > 50) {
      $("#jquery_jplayer").jPlayer("stop");
    }
  }
});

I'm in the middle of converting my site to jPlayer 2.0 and the changes in event binding will make this answer unhelpful going forward. Maybe it can give you a head start though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号