2

我正在使用 load api 调用来使用新的播放列表更新播放列表。但是这个调用会停止当前播放的视频。有没有办法避免这种情况?

我也在这里尝试了这个建议,但是获取当前位置并将视频重新加载到同一位置有很大的延迟。

在这里工作小提琴

这是我修改播放列表的功能

var addItemToPlaylist = function(){
    var playlist = jwplayer("myElement").getPlaylist();
    playlist.push(playlist[0]);
    var curpos = jwplayer().getPosition();
    jwplayer("myElement").onPlaylist(function () {
        console.log("Seeking here");
        jwplayer().seek(curpos);
    })
    jwplayer("myElement").load(playlist);
}
4

1 回答 1

1

这是我能想到的最好的解决方法:

<!DOCTYPE html>
<html>
<head>
<title>Add to Playlist</title>
<script src="http://p.jwpcdn.com/6/8/jwplayer.js"></script>
<style type="text/css">
body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
}
a {
    color:#000000;
}
ul,li {
    list-style:none;
}
</style>
<script type="text/javascript">
var addVideo = function(videoUrl, videoThumb, videoTitle, videoDesc){
    var playlist = jwplayer().getPlaylist();
    var newItem = {
        file: videoUrl,
        image: videoThumb,
        title: videoTitle,
        description: videoDesc
    };
    if(jwplayer().getState() != "PLAYING"){
        playlist.push(newItem);
        jwplayer().load(playlist);
    } else {
        playlist.push(newItem);
        var curpos = jwplayer().getPosition();
        jwplayer().onPlaylist(function(){
            jwplayer().seek(curpos);
        });
        jwplayer().load(playlist).onPlaylist(function(){
            jwplayer().seek(curpos);
        });
    }
}
</script>
</head>
<body>
<div id="myElement"></div>
<script>
jwplayer("myElement").setup({
      playlist: [{
        file: "http://content.bitsontherun.com/videos/3XnJSIm4-640.mp4",
        image: "http://assets-jp.jwpsrv.com/thumbs/3XnJSIm4-640.jpg",
        title: "Sintel Trailer",
        description: "Sintel is a fantasy CGI movie from the Blender Open Movie Project."
      },{
        file: "http://content.bitsontherun.com/videos/i8oQD9zd-640.mp4",
        image: "http://assets-jp.jwpsrv.com/thumbs/i8oQD9zd-640.jpg",
        title: "Tears of Steel Trailer",
        description: "A complete open pipeline was used to produce this visual effect film."
      },{
        file: "http://content.bitsontherun.com/videos/bkaovAYt-640.mp4",
        image: "http://assets-jp.jwpsrv.com/thumbs/bkaovAYt-640.jpg",
        title: "Big Buck Bunny Trailer",
        description: "This animated film is made using free and open source software."
      },{
        file: "http://content.bitsontherun.com/videos/kaUXWqTZ-640.mp4",
        image: "http://assets-jp.jwpsrv.com/thumbs/kaUXWqTZ-640.jpg",
        title: "Elephants Dream Trailer",
        description: "This is the worlds first open movie, made entirely with Blender."
      }],
      width: 700,
      height: 240,
      listbar: {
        position: "right",
        size: 280
      }
    });
</script>
<p>Click on one of the links below to add an item to the player:</p>
<ul>
<li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/yj1shGJB-60830.mp4', 'http://content.bitsontherun.com/thumbs/yj1shGJB-320.jpg', 'Sintel trailer', 'Sintel is a fantasy CGI movie from the Blender Open Movie Project.'); return false;">Add the Sintel trailer to the playlist</a></li>
<li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/i8oQD9zd-kNspJqnJ.mp4', 'http://content.bitsontherun.com/thumbs/i8oQD9zd-640.jpg', 'Tears of Steel Trailer', 'A complete open pipeline was used to produce this visual effect film.'); return false;">Add the Tears of Steel trailer to the playlist</a></li>
<li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/bkaovAYt-640.mp4', 'http://assets-jp.jwpsrv.com/thumbs/bkaovAYt-640.jpg', 'Big Buck Bunny Trailer', 'This animated film is made using free and open source software.'); return false;">Add the Big Buck Bunny trailer to the playlist</a></li>
<li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/kaUXWqTZ-640.mp4', 'http://assets-jp.jwpsrv.com/thumbs/kaUXWqTZ-640.jpg', 'Elephants Dream Trailer', 'This animated film is made using free and open source software.'); return false;">Add the Elephants Dream trailer to the playlist</a></li>
</ul>
</body>
</html>
于 2014-05-19T21:57:33.917 回答