jQuery停止视频脚本

jQuery stop video script

本文关键字:脚本 视频 jQuery      更新时间:2023-09-26

这个脚本运行得很好,但它所做的是在启动新视频时停止播放视频的实例。当调用函数stopAllButMe();时,我该如何重写它以停止播放视频的所有实例?

function stopAllButMe(playerState, player) {
    if (playerState=='PLAYING') {
        var myId = player.getId();
        projekktor('*').each(function() {
            if (this.getId()!==myId) {
                this.setStop();
            }
        });
    }
}
projekktor('*').each(function() {
    this.addListener('state', stopAllButMe);
});
function stopAllButMe(playerState) {
  if (playerState=='PLAYING') {
    projekktor('*').each(function() {
      this.setStop();
    });
  }
}
projekktor('*').each(function() {
  this.addListener('state', stopAllButMe);
});

"if"语句正在根据输入进行检查。

function stopAllButMe (state, player) {
    //iterate through each of the `<video>` elements
    $.each($('video'), function () {
        //check if the current iteration is the same element that got passed into this function
        if (this.id != player.id) {
            //stop any `<video>` element that isn't the one passed into this function
            this.stop();
        }
    });
}
//find each `<video>` element and add an event handler for the `state` event
$('video').bind('state', stopAllButMe);

这假设每个<video>标签都有自己唯一的ID。