JW Player停止播放多个视频

时间:2017-01-09 10:02:01

标签: javascript html video jwplayer

我在同一页面中有多个视频。但是 - 我可以同时播放多个视频并一起听取每个视频。当我开始播放另一个视频时 - 正在播放的视频必须关闭。

<div class="tab-pane active" id="abc"><div class="panel-body">
    <script src="//content.jwplatform.com/players/abc.js"></script></div>
</div>
 <div class="tab-pane" id="def"><div class="panel-body">
    <script src="//content.jwplatform.com/players/def.js"></script></div>
</div>
<div class="tab-pane" id="ghi"><div class="panel-body">
 <script src="//content.jwplatform.com/players/ghi.js"></script></div>
</div>
<div class="tab-pane" id="jkl"><div class="panel-body">
   <script src="//content.jwplatform.com/players/jkl.js"></script>   </div>
</div>

2 个答案:

答案 0 :(得分:1)

以下是HTML的外观:

jwplayer("player1").setup({
  playlist: [{
    file: "bbb_sunflower_1080p_60fps_normal.mp4"
    }],
        width: 300,
        aspectratio: '16:9',
        events: {
          onPlay: function() {
            jwplayer('player2').stop();jwplayer('player3').stop();
          },
          onComplete: function() {
            //something can happen at the end of the video here if you'd like.
          }
        },
      });
//etc.

这是你的js应该做的事情。密切关注onPlay事件:

deps = {
    'A': ['B', 'C', 'D'],
    'B': ['C', 'E'],
    'C': ['D', 'F'],
    'D': ['C', 'G'],
    'E': ['A'],
    'H': ['N'],
}

def get_all_deps(item):
    todo = set(deps[item])
    rval = set()
    while todo:
        subitem = todo.pop()
        if subitem != item:  # don't add start item to the list
            rval.add(subitem)
            to_add = set(deps.get(subitem,[]))
            todo.update(to_add.difference(rval))
    return sorted(rval)

print(get_all_deps('A'))
print(get_all_deps('E'))
print(get_all_deps('H'))

演示:http://codepen.io/simsketch/pen/LxpmWx

希望这有帮助!

答案 1 :(得分:0)

JW Player有一个代码示例:

https://developer.jwplayer.com/jw-player/demos/basic/mutually-exclusive/

虽然您的设置似乎已关闭,但您不应该拥有多个播放器库,因此很可能您有多个单行嵌入,这也不是最好的选择。我建议使用与上述文档中描述的代码类似的代码,您有一个云托管播放器并致电

jwplayer('DIV_ID').setup(); 

每个玩家。