Browse Source

Fix wrong index reference in player close and change from playerStop to playerPause

Joachim M. Giæver 4 years ago
parent
commit
74af0412ac
1 changed files with 9 additions and 6 deletions
  1. 9 6
      index.html

+ 9 - 6
index.html

@@ -12,6 +12,7 @@
 
         .player {
             position: relative;
+            z-index: 2;
             width: 70vw;
             margin: 0 auto;
         }
@@ -96,13 +97,14 @@
                 var playerOpen = function (i, player) {
                     if (!ytp[i])
                         return;
-
+                    
                     // Remove thumb and show iframe
                     player.find('.thumb').outEffect();
                     player.find('iframe').inEffect({
                         complete: function () {
                             // When fully opened, plat video and change cursor
-                            ytp[i].playVideo()
+                            if (ytp[i].getPlayerState() != YT.PlayerState.PLAYING)
+                                ytp[i].playVideo()
                             player.removeClass('play loading').addClass('stop');
                         }
                     });
@@ -110,7 +112,7 @@
                     // Close all the players that might be open.
                     $('.player').each(function (idx) {
                         if (i == idx) return;
-                        playerClose(i, $(this));
+                        playerClose(idx, $(this));
                     })
                 }
 
@@ -118,13 +120,14 @@
                 var playerClose = function (i, player) {
                     if (!ytp[i])
                         return;
-                    
-                    // Stop the video
-                    ytp[i].stopVideo();
 
                     // Hide iframe and show thumg
                     player.find('iframe').outEffect()
                     player.find('.thumb').inEffect(function() {
+                        // Stop the video; if playing
+                        if (ytp[i].getPlayerState() == YT.PlayerState.PLAYING)
+                            ytp[i].pauseVideo();
+
                         player.removeClass('stop loading').addClass('play');
                     });
                 }