Created
April 25, 2017 07:23
-
-
Save myungseokang/1083ed530c826670f6c244616ee9283d to your computer and use it in GitHub Desktop.
Youtube player with loop using Iframe API
This file contains 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
<script> | |
// Inject this code | |
var tag = document.createElement('script'); | |
tag.src = "https://www.youtube.com/iframe_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
var player; | |
function onYouTubeIframeAPIReady() { | |
player = new YT.Player('player', { | |
videoId: 'WANTED_VIDEO_ID', | |
events: { | |
'onStateChange': onPlayerStateChange | |
} | |
}); | |
} | |
function onPlayerStateChange(e) { | |
if (e.data === YT.PlayerState.ENDED) { | |
player.playVideo(); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment