gpt4 book ai didi

javascript - 播放播放列表中特定时间位置的歌曲

转载 作者:行者123 更新时间:2023-11-28 00:03:33 25 4
gpt4 key购买 nike

我正在使用jPlayer插件。

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

这是一个示例 jsFiddle .

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

如何获取当前音频tagnumber来设置jPlayer播放列表中每首歌曲的currentTime?

最佳答案

解决方案

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,因为根据manual

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.

演示

参见this jsFiddle用于代码和演示。

关于javascript - 播放播放列表中特定时间位置的歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31564753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com