Advertisement
Guest User

YouTubePlayerSM

a guest
Oct 28th, 2016
416
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. var tag = document.createElement('script');
  3. tag.src = 'https://www.youtube.com/player_api';
  4. var firstScriptTag = document.getElementsByTagName('script')[0];
  5. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  6. var player;
  7.  function onYouTubeIframeAPIReady() {
  8.  player = new YT.Player('player', {
  9.  events: {
  10.  'onReady': onPlayerReady,
  11.  'onStateChange': onPlayerStateChange
  12.  }
  13.  });
  14.  }
  15.  function onPlayerReady(event) {
  16. smEvent('video_player_ready');
  17.  }
  18.  var firstPlay = false;
  19.  function onPlayerStateChange(event) {
  20.  if (event.data == YT.PlayerState.PLAYING) {
  21. if (!firstPlay)
  22. smEvent('video_started');
  23. firstPlay = true;
  24.  }
  25. if (event.data == YT.PlayerState.PAUSED) {
  26. smEvent('video_paused');
  27. }
  28. if (event.data == YT.PlayerState.ENDED) {
  29. smEvent('video_ended');
  30. }
  31.  }
  32. </script>
Advertisement
RAW Paste Data Copied
Advertisement