简体   繁体   English

在播放列表的特定时间位置播放每首曲目

[英]Play each track at specific time position from a playlist

I want users to be able, to continue a track from where they paused or stopped it last time.我希望用户能够从他们上次暂停或停止的地方继续曲目。 I save a users key into a cookie, and store the chosen tracks and elapsed times into db.我将用户密钥保存到 cookie 中,并将选择的曲目和经过时间存储到 db 中。 Then before a activated song is going to play the current time should be set at the retrieven elapsed time:然后在播放激活的歌曲之前,应将当前时间设置为检索到的经过时间:

ie. IE。 User lately ilstened to these two songs用户最近对这两首歌感兴趣

song1.mp3n, stopped at 2 sec Song1.mp3n,停在 2 秒

song3.mp3 stopped at 100 sec song3.mp3 停在 100 秒

I found some information at.我在那里找到了一些信息。 Play song at specific time position from a playlist 在播放列表中的特定时间位置播放歌曲

I came up with the following code:我想出了以下代码:

$jplay= <<<EOD
var jp = $('#jquery_jplayer_1pl');
jp.on($.jPlayer.event.setmedia,  function(e){
    // For first track (0) - 2 sec, second track (1) - 3 sec, etc.
    //var time = myPlaylist.current + {$time_elapsed};
    var time = {$time_elapsed};

    // Jump to desired time
    setTimeout(function(){ 
       jp.jPlayer( "play", time); 
    }, 100);
});
EOD;

But this only works with single player version, unless the last track, the user listended to, could be activated or played automatically.但这仅适用于单人播放器版本,除非用户收听的最后一首曲目可以被激活或自动播放。 Otherwise every song strts at the same time position.否则每首歌曲都在同一时间位置。

Therefore I think I could use "myPlaylist.play(0);"因此我想我可以使用“myPlaylist.play(0);” or "myPlaylist.play(2);", but I cannot find out how.或“myPlaylist.play(2);”,但我不知道怎么做。

To be more precise, I want to start several tracks at different elapsed time positions, when they are activated.更准确地说,当它们被激活时,我想在不同的经过时间位置开始几个轨道。

Thanks.谢谢。

To make this work for the playlist player version of jplayer, after days I found out the following solution myself, based on jquery and ajax.为了使其适用于 jplayer 的播放列表播放器版本,几天后我自己基于 jquery 和 ajax 找到了以下解决方案。

$("#jquery_jplayer_1pl").bind($.jPlayer.event.setmedia, function(event) {

    $.ajax({
        type: "GET",
        url: 'media-progress-ajax-funcs1.php',
        data: {
            guid: myPlaylist.playlist[myPlaylist.current].mp3, 
            bkmk_key: '<?php echo $bkmk_key; ?>', 
        },
        contentType: "application/json; charset=utf-8",           
        dataType: "json",
        success: function(response) {
            playtrack(response['timeElapsed']);
        }
    });
});

function playtrack(elapsed) {
    if (elapsed) {
        var jp = $('#jquery_jplayer_1pl');
        var time = parseInt(elapsed);
        // Jump to desired time
        setTimeout(function(){ 
           jp.jPlayer( "pause", time);
        }, 100);
    }
}

Explanation:解释:

        data: {
            guid: myPlaylist.playlist[myPlaylist.current].mp3, 
            bkmk_key: '<?php echo $bkmk_key; ?>', 
        }

The variable bkmk_key is derived from a cookie and unique for a cetain user.变量 bkmk_key 派生自 cookie,对于 cetain 用户是唯一的。 The ajax function script 'media-progress-ajax-funcs1.php' is searching for the userkey and corresponding media filename (guid) the user has paused after a certain time (elapsed time from event.jPlayer.status.currentTime) and returns the elapsed time value if the media is set (event:setmedia). ajax 函数脚本'media-progress-ajax-funcs1.php' 正在搜索用户在一段时间后(从 event.jPlayer.status.currentTime 开始的经过时间)暂停的用户密钥和相应的媒体文件名(guid)并返回如果设置了媒体,则经过的时间值 (event:setmedia)。 It will start playing by clicking play from the latest position, so the user has not to search for it.它将通过从最新位置单击播放开始播放,因此用户不必搜索它。

I do not mention howto get the elapsed time, after the player is paused, and store it into the database.我没有提到如何在播放器暂停后获取经过的时间,并将其存储到数据库中。 If you are interested in this part of my code you will have to ask.如果您对我的代码的这一部分感兴趣,您将不得不问。

I hope that someone finds this helpful.我希望有人觉得这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM