SoundCloud播放器具有默認功能,當用戶啓動播放器時,它會自動暫停所有正在播放的其他播放器。 (例如:http://jsfiddle.net/Vx6hM/)。如何阻止嵌入式Youtube視頻同時播放
我試圖重新創建嵌入式YouTube視頻,通過正常的嵌入代碼動態添加。
使用此:https://stackoverflow.com/a/7513356/938089 這:https://stackoverflow.com/a/7988536/1470827
我能夠遠遠地得到這樣的:
function chain(){
$('.post').each(function(){
var player_id = $(this).children('iframe').attr("id");
var other_player_id = $(this).siblings().children('iframe').attr("id");
player = new YT.Player(player_id, {
events:
{
'onStateChange': function (event)
{
if (event.data == YT.PlayerState.PLAYING)
{ callPlayer(other_player_id , 'pauseVideo');
alert('Trying to pause: ' + other_player_id);
}
}
}
});
});
}
這裏有一個JS斌用了一半的工作:http://jsbin.com/oxoyes/2/edit
目前,它唯一的召喚其中一個球員。我需要它暫停所有其他玩家,除了玩牌之外。
此外,如何清理和/或做不同/更好的任何提示,都歡迎。我對JavaScript仍然很陌生,所以我甚至不確定我會以正確的方式開展工作。
謝謝!
我寫了一篇博客文章,詳細介紹了響應各種Youtube播放器API事件的完整工作示例:http://www.objectpartners.com/2013/08/21/triggering-a-youtube-video-從點擊一個按鈕的圖像和替換完成時/ –