반응형
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', { height: '390', width: '640', videoId: 'HgruWmbIlq8', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } function onPlayerReady(event) { event.target.playVideo(); } var done = false; function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING && !done) { setTimeout(stopVideo, 6000); done = true; } } function stopVideo() { player.stopVideo(); }
반응형
'프로그래밍 > JavaScipt' 카테고리의 다른 글
javascript youtube data search api v3 리스트검색 (1) | 2016.06.02 |
---|---|
javascript prototype 이해 (0) | 2016.06.01 |
javascript datediff 날짜차이계산함수 (0) | 2016.04.27 |
javascript get date time (0) | 2016.03.28 |
javascript byte단위 자르기 (0) | 2016.03.28 |