Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. var isReady=0;
  2. var player;
  3. function onYouTubeIframeAPIReady() {
  4. isReady=1;
  5. }
  6.  
  7. // 4. The API will call this function when the video player is ready.
  8. function onPlayerReady(event) {
  9. event.target.playVideo();
  10. }
  11.  
  12. // 5. The API calls this function when the player's state changes.
  13. // The function indicates that when playing a video (state=1),
  14. // the player should play for six seconds and then stop.
  15. var done = false;
  16. function onPlayerStateChange(event) {
  17. if (event.data == YT.PlayerState.PLAYING && !done) {
  18. setTimeout(stopVideo, 6000);
  19. done = true;
  20. }
  21. }
  22. function stopVideo() {
  23. player.stopVideo();
  24. }
  25. function onModalOpen(){
  26. if(isReady==1){
  27. player = new YT.Player('player', {
  28. height: '390',
  29. width: '640',
  30. videoId: 'u1zgFlCw8Aw',
  31. events: {
  32. 'onReady': onPlayerReady,
  33. 'onStateChange': onPlayerStateChange
  34. }
  35. });
  36. }
  37. }
  38. function onModalClose(){
  39. player=null;
  40. }
Add Comment
Please, Sign In to add comment