Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>test page</title>
  5.   </head>
  6.  
  7.   <body>
  8.     <h3>Test page</h3>
  9.     <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
  10.     <div id="points-container"><span id="points">0</span> of 750</div>
  11.     <div id="player"></div>
  12.  
  13.     <script>
  14.      var videoDuration = 0;
  15.  
  16.       // 2. This code loads the IFrame Player API code asynchronously.
  17.       var tag = document.createElement('script');
  18.  
  19.       tag.src = "https://www.youtube.com/iframe_api";
  20.       var firstScriptTag = document.getElementsByTagName('script')[0];
  21.       firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  22.  
  23.       // 3. This function creates an <iframe> (and YouTube player)
  24.       //    after the API code downloads.
  25.       var player;
  26.       function onYouTubeIframeAPIReady() {
  27.         player = new YT.Player('player', {
  28.           height: '390',
  29.           width: '640',
  30.           videoId: 'M7lc1UVf-VE',
  31.           events: {
  32.             'onReady': onPlayerReady,
  33.             'onStateChange': onPlayerStateChange
  34.           }
  35.         });
  36.       }
  37.  
  38.       // 4. The API will call this function when the video player is ready.
  39.       function onPlayerReady(event) {
  40.         event.target.playVideo();
  41.       }
  42.  
  43.       var isCouting = false;
  44.       function onPlayerStateChange(event) {
  45.         if (event.data == YT.PlayerState.PLAYING) {
  46.       videoDuration = player.getDuration();
  47.           window.setInterval(logCurrentTimeVideo, 2000);
  48.       isCounting = true;
  49.         } else {
  50.       isCounting = false;
  51.     }
  52.       }
  53.       function logCurrentTimeVideo() {
  54.     if (isCounting) {
  55.       console.log(player.getCurrentTime());
  56.       console.log(videoDuration);
  57.       console.log((player.getCurrentTime()/videoDuration)*100 + "%");
  58.       document.getElementById("points").innerHTML = "" + (Math.round((player.getCurrentTime()/videoDuration)*750));
  59.     }
  60.       }
  61.     </script>
  62.   </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement