2012-02-01 131 views
0

此脚本完美地工作,但它所做的是停止正在播放视频的实例,如果新视频启动。当函数stopAllButMe();被调用时,我将如何重写该函数以停止播放视频的所有实例?jQuery停止视频脚本

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); 
}); 

回答

0
function stopAllButMe(playerState) { 
    if (playerState=='PLAYING') { 
    projekktor('*').each(function() { 

     this.setStop(); 

    }); 
    } 
} 
projekktor('*').each(function() { 
    this.addListener('state', stopAllButMe); 
}); 

的 '如果' 语句检查对输入。

+0

这种作品...除了你甚至不能在视频上点击播放,因为脚本自动立即停止它。 – Blainer 2012-02-01 22:25:14

+0

有没有办法让这个脚本只在被调用时才运行? – Blainer 2012-02-01 22:28:54

0
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。