SoundCloud players have a default feature, when a user starts the player, it automatically pauses all the others that are currently playing. (example: http://jsfiddle.net/Vx6hM/ ).
I am trying to recreate this with embedded YouTube videos that are added dynamically through regular embed code.
Using this: https://stackoverflow.com >
I can go this far:
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); } } } }); }); }
Here JS Bin works with him halfway: http://jsbin.com/oxoyes/2/edit
Currently, his only challenge to one of the players. I need to pause ALL other players except the game.
In addition, any advice on how to clean it and / or do it differently / better is welcome. I'm still very new to javascript, so I'm not even sure if I will go that route.
Thanks!
source share