jplayer play between certain percents of time in jquery

こ雲淡風輕ζ 提交于 2019-12-11 09:27:51

问题


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 can 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


回答1:


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.



来源:https://stackoverflow.com/questions/4599929/jplayer-play-between-certain-percents-of-time-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!