Created
May 12, 2014 17:28
-
-
Save 64lines/53852cb12a168299ac40 to your computer and use it in GitHub Desktop.
Create a video with Youtube Player API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="player"></div> | |
| <script src="http://www.youtube.com/player_api"></script> | |
| <script> | |
| // create youtube player | |
| var player; | |
| function onYouTubePlayerAPIReady() { | |
| player = new YT.Player('player', { | |
| height: '390', | |
| width: '640', | |
| videoId: '0Bmhjf0rKe8', | |
| events: { | |
| 'onReady': onPlayerReady, | |
| 'onStateChange': onPlayerStateChange | |
| } | |
| }); | |
| } | |
| // autoplay video | |
| function onPlayerReady(event) { | |
| event.target.playVideo(); | |
| } | |
| // when video ends | |
| function onPlayerStateChange(event) { | |
| if(event.data === 0) { | |
| alert('done'); | |
| } | |
| } | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment