더 나은 프로그래머가 되자

유튜브 iframe 영상 제어(재생,일시정지,정지) 본문

API/유투브

유튜브 iframe 영상 제어(재생,일시정지,정지)

greathuman 2019. 8. 12. 14:08

<script type="text/javascript">
$(function(){ 
	$("#pause").click(function(){
		//playVideo=재생, pauseVideo=일시정지, stopVideo=정지 
		$("iframe")[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*'); 
	});
});
</script>

<iframe width="100%" height="315" src="영상주소?enablejsapi=1&version=3&playerapiid=ytplayer&ecver=2&vq=hd720&rel=0" frameborder="0" allow="accelerometer;encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

<button type="type" id="pause">일시정지</button>

 

 

출처 : https://kunoo.tistory.com/entry/Tip-Youtube-iframe-%EC%9D%B4%EB%B2%A4%ED%8A%B8-%EC%A0%9C%EC%96%B4

Comments