Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <body>
  4.  
  5.     <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
  6.     <div id="playerIPN"></div>
  7.     <button id="ytIPN">Button</button>
  8.     <script>
  9.      // 2. This code loads the IFrame Player API code asynchronously.
  10.       var tag = document.createElement('script');
  11.  
  12.       tag.src = "https://www.youtube.com/iframe_api";
  13.       var firstScriptTag = document.getElementsByTagName('script')[0];
  14.       firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  15.  
  16.       // 3. This function creates an <iframe> (and YouTube player)
  17.       //    after the API code downloads.
  18.       var player;
  19.       function onYouTubeIframeAPIReady() {
  20.         player = new YT.Player('playerIPN', {
  21.           height: '360',
  22.           width: '640',
  23.           videoId: 'wzJ909w6Hbo',
  24.           events: {
  25.             'onReady': onPlayerReady,
  26.             'onStateChange': onPlayerStateChange
  27.           }
  28.         });
  29.       }
  30.  
  31.       // 4. The API will call this function when the video player is ready.
  32.       function onPlayerReady(event) {
  33.         event.target.playVideo();
  34.       }
  35.  
  36.       // 5. The API calls this function when the player's state changes.
  37.       //    The function indicates that when playing a video (state=1),
  38.       //    the player should play for six seconds and then stop.
  39.       var done = false;
  40.       function onPlayerStateChange(event) {
  41.         if (event.data == YT.PlayerState.UNSTARTED && !done) {
  42.           stopVideo();
  43.           done = true;
  44.         }
  45.       }
  46.     function stopVideo() {
  47.         player.stopVideo();
  48.     }
  49.     window.onload = function() {
  50.         var iframe = document.getElementById("playerIPN");
  51.         document.getElementById("ytIPN").addEventListener("click", function( e ) {
  52.           e.preventDefault();
  53.           iframe.src += "&autoplay=1";
  54.           console.log(iframe.src);
  55.         }, false);
  56.     };
  57.  
  58.     </script>
  59.   </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement