Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在不停止当前正在播放的视频的情况下更新JWPlayer播放列表_Javascript_Jquery_Video_Jwplayer_Jwplayer6 - Fatal编程技术网

Javascript 在不停止当前正在播放的视频的情况下更新JWPlayer播放列表

Javascript 在不停止当前正在播放的视频的情况下更新JWPlayer播放列表,javascript,jquery,video,jwplayer,jwplayer6,Javascript,Jquery,Video,Jwplayer,Jwplayer6,我正在使用load api调用用新的播放列表更新播放列表。但此呼叫会停止当前播放的视频。有没有办法避免这种情况 我也尝试过这个建议,但是获取当前位置并将视频重新加载回同一位置会有很大的延迟 工作小提琴 这是我修改播放列表的功能 var addItemToPlaylist = function(){ var playlist = jwplayer("myElement").getPlaylist(); playlist.push(playlist[0]); var curp

我正在使用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);
}

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

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

添加到播放列表
身体{
字体系列:无衬线;
保证金:0;
填充:0;
}
a{
颜色:#000000;
}
李先生{
列表样式:无;
}
var addVideo=函数(videoUrl、videoThumb、videoTitle、videoDesc){
var playlist=jwplayer().getPlaylist();
var newItem={
文件:videoUrl,
图片:videoThumb,
标题:视频标题,
描述:视频描述
};
如果(jwplayer().getState()!=“播放”){
playlist.push(newItem);
jwplayer().load(播放列表);
}否则{
playlist.push(newItem);
var curpos=jwplayer().getPosition();
jwplayer().onPlaylist(函数(){
jwplayer().seek(curpos);
});
jwplayer().load(播放列表).onPlaylist(函数()){
jwplayer().seek(curpos);
});
}
}
jwplayer(“myElement”).setup({
播放列表:[{
文件:“http://content.bitsontherun.com/videos/3XnJSIm4-640.mp4",
图像:“http://assets-jp.jwpsrv.com/thumbs/3XnJSIm4-640.jpg",
标题:“辛特尔拖车”,
描述:“辛特尔是一部来自Blender开放电影项目的奇幻CGI电影。”
},{
文件:“http://content.bitsontherun.com/videos/i8oQD9zd-640.mp4",
图像:“http://assets-jp.jwpsrv.com/thumbs/i8oQD9zd-640.jpg",
标题:“钢制拖车的撕裂”,
描述:“一个完整的开放管道被用来制作这部视觉效果电影。”
},{
文件:“http://content.bitsontherun.com/videos/bkaovAYt-640.mp4",
图像:“http://assets-jp.jwpsrv.com/thumbs/bkaovAYt-640.jpg",
标题:“大公兔拖车”,
描述:“这部动画电影是使用免费的开源软件制作的。”
},{
文件:“http://content.bitsontherun.com/videos/kaUXWqTZ-640.mp4",
图像:“http://assets-jp.jwpsrv.com/thumbs/kaUXWqTZ-640.jpg",
标题:“大象梦预告片”,
描述:“这是世界上第一部完全用Blender制作的开放式电影。”
}],
宽度:700,
身高:240,
列表栏:{
位置:“对”,
尺码:280
}
});
单击以下链接之一向播放机添加项目:


加载新项目时,它将始终停止播放,恐怕无法更改此行为。