Advertisement
rAthus

Javascript : action lorsqu'un vidéo Youtube se termine

Jun 1st, 2015
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.65 KB | None | 0 0
  1. <div id="player"></div>
  2. <script src="http://www.youtube.com/player_api"></script>
  3. <script>
  4.     // create youtube player
  5.     var player;
  6.     function onYouTubePlayerAPIReady()
  7.     {
  8.         player = new YT.Player('player',
  9.         {
  10.             width: '560',
  11.             height: '315',
  12.             videoId: 'g-JWRqzLZRk',
  13.             events:
  14.             {
  15.                 'onReady': onPlayerReady,
  16.                 'onStateChange': onPlayerStateChange
  17.             }
  18.         });
  19.     }
  20.     // autoplay video
  21.     function onPlayerReady(event)
  22.     {
  23.         event.target.playVideo();
  24.     }
  25.     // when video ends
  26.     function onPlayerStateChange(event)
  27.     {        
  28.         if (event.data===0)
  29.         {          
  30.             /** here put code to be triggered when video ends ! **/
  31.         }
  32.     }
  33. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement