在播放列表中的特定时间播放歌曲 [英] Play song at specific time position from a playlist

查看:85
本文介绍了在播放列表中的特定时间播放歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jPlayer 插件.

例如,播放列表中有13首歌曲.我想为每首歌曲设置开始时间(currentTime),例如:第一首歌曲从2秒开始,第二首歌曲从3秒开始,第五首歌曲从4秒开始.

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.

以下是示例 jsFiddle .

在此示例中,我添加了 var tag = $('.audio-tag audio')[0]; ,以全局查找当前播放的歌曲,但该歌曲不在jPlayer插件中.

In this example I added var tag = $('.audio-tag audio')[0]; to find current playing song globally but it is out of jPlayer plugin.

如何获取当前音频标签& number 可以为jPlayer播放列表的每首歌曲设置currentTime吗?

How to get current audio tag & number to set currentTime for each song of jPlayer playlist?

推荐答案

解决方案

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);
});  

注释

需要调用 setTimeoout ,因为根据手册

如果使用 time 参数在 setMedia 命令之后立即发布,并且当浏览器使用HTML5解决方案时,此命令最初将失败并且内部超时为设置为每100毫秒重试该命令,直到成功为止.

If issued immediately after a setMedia command, with the time 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.

演示

有关代码和演示,请参见此jsFiddle .

See this jsFiddle for code and demonstration.

这篇关于在播放列表中的特定时间播放歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆