Streaming live at 10am (PST)

Pausing Embedded Youtube Video with Script Problem


#1

Hi Guys,

I'm using tips from this topic to learn how to stop a youtube video within a modal when closing the modal.

The first video works correctly, but the second doesn't work when closing the modal and reopening it again.

Do you see what I've done wrong? I'd like this to work for every video on the site.

Thanks,
Will

Site: http://tim-1.webflow.io/
Share link: https://preview.webflow.com/preview/tim-1?preview=7d85e0eb7a8cff816109959794022d2d


#2

This pauses the video where iframe.id = "player1". Where did you copy this from?

yt_players['player1'].pauseVideo();

#3

After scouring the web, this turned out to be the best solution:

<script>
  
  $(function(){

				var yt_int, yt_players={},
				    initYT = function() {
				        $(".ytplayer").each(function() {
				            yt_players[this.id] = new YT.Player(this.id);
				        });
				    };

				$.getScript("//www.youtube.com/player_api", function() {
				    yt_int = setInterval(function(){
				        if(typeof YT === "object"){
				            initYT();
				            clearInterval(yt_int);
				        }
				    },500);
				});

				$('.pause').on('click', function(){
					yt_players['player1'].pauseVideo();
				});
    
    			$('.pause2').on('click', function(){
					yt_players['player2'].pauseVideo();
				});
        
    			$('.pause3').on('click', function(){
					yt_players['player3'].pauseVideo();
				});
        
    			$('.pause4').on('click', function(){
					yt_players['player4'].pauseVideo();
				});
        
    			$('.pause5').on('click', function(){
					yt_players['player5'].pauseVideo();
				});
        
    			$('.pause6').on('click', function(){
					yt_players['player6'].pauseVideo();
				});
        
    			$('.pause7').on('click', function(){
					yt_players['player7'].pauseVideo();
				});
        
    			$('.pause8').on('click', function(){
					yt_players['player8'].pauseVideo();
				});
        
    			$('.pause9').on('click', function(){
					yt_players['player9'].pauseVideo();
				});
        
    			$('.pause10').on('click', function(){
					yt_players['player10'].pauseVideo();
				});
        
    			$('.pause11').on('click', function(){
					yt_players['player11'].pauseVideo();
				});


			});
  
</script>