2013-02-21 1 views
4

YouTube 동영상을로드 한 다음 음소거, 재생, 일시 중지 및 음소거를 즉시 취소하고 싶습니다. 이렇게하면 큰 재생 버튼이없는 동영상을 사용자에게 제공하고 하단에 컨트롤이 표시되기를 바랍니다.YouTube iframe 플레이어가 YouTubePlayerReady를로드 할 때 왜 전화를 걸지 않는 이유가 무엇입니까?

<script type="text/javascript"> 
function onYouTubePlayerReady(playerid) 
{ 
    mutePlayPauseUnmute(playerid); 
} 
function onYouTubePlayerAPIReady(playerid) 
{ 
    mutePlayPauseUnmute(playerid); 
} 
function onYouTubeIframeAPIReady(playerid) 
{ 
    mutePlayPauseUnmute(playerid) 
} 
function onPlayerReady(playerid) 
{ 
    mutePlayPauseUnmute(playerid) 
} 

function mutePlayPauseUnmute(playerid) 
{ 
    var player = document.getElementById(playerid); 
    player.mute(); 
    player.playVideo(); 
    player.pauseVideo(); 
    player.unMute(); 
} 
</script> 
<iframe id="quotedVideo1" type="text/html" width="246" height="160" src="https://www.youtube.com/embed/NWHfY_lvKIQ?modestbranding=1&rel=0&showinfo=0&autohide=1&iv_load_policy=3&theme=light&enablejsapi=1&playerapiid=quotedVideo1" frameborder="0"> <!-- Magic Comment --> </iframe> 

그러나, 검사에, 어느 쪽도 onYouTubePlayerReady, onYouTubePlayerAPIReadyonYouTubeIframeAPIReadyonPlayerReady가 없으며, mutePlayPauseUnmute 이제까지라고하지 :이 작업을 수행하기 위해, 나는 다음과 같은 코드가 있습니다. 내가 뭘 잘못 했니?https://developers.google.com/youtube/js_api_reference#onYouTubePlayerReady에 따르면 작동해야하는 것처럼 보이지만 그렇지 않습니다.

+0

주목할 가치 : "플레이어는 200x200 픽셀 이상이어야합니다." –

+0

알아요 ... 클라이언트가 정확하게이 크기가되도록 요구합니다 :/ – Supuhstar

답변

11

두 가지 다른 플레이어 API를 혼동스럽게 여기고 있습니다.

iframe 플레이어을 사용 하시겠습니까? 그렇다면 다음을 살펴보십시오. https://developers.google.com/youtube/iframe_api_reference.

onYouTubePlayerReady을 정의하는 대신 onYouTubeIframeAPIReady 메서드를 정의한 다음 플레이어를 만들고 onPlayerReady 콜백을 할당 할 수 있습니다. 대신은 iframe을 쓰고있어 이후의 문서에서 지적

var tag = document.createElement('script'); 
tag.src = o.protocol + "://www.youtube.com/iframe_api"; 
var firstScriptTag = document.getElementsByTagName('script')[0]; 
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

가치 :

는 호출 할 onYouTubeIframeAPIReady 위해서는, 당신은 iframe이 플레이어 API에 대한 자바 스크립트를 포함하고 있는지 확인 자바 스크립트를 사용하는 당신을 위해 그렇게 : 태그를 쓰기 할 경우

는, 당신은 YT.Player 객체를 생성 할 때 폭과 0의 값을 지정할 필요가 없습니다 태그의 속성으로 지정된높이 또는 src URL에 지정된 videoId 및 플레이어 매개 변수 당신의 mutePlayPauseUnmute 기능에서 또한

..

playerid.mute(); 
playerid.playVideo(); 
playerid.pauseVideo(); 
playerid.unMute(); 

당신은 전술 한 바와 같이 playerid 반대로 player의 방법의 실제를 트리거 할 수 있습니다.

+0

왜 태그의 너비와 높이를 넣는 것에 대해 문서의 해당 부분을 인용하셨습니까? 내가 그랬어 ... – Supuhstar

+0

질문이 업데이 트되었습니다 – Supuhstar

+0

iframe을 플레이어에 대해 물어볼 때 당신은 여전히 ​​JS API를 참조하고 있습니다. 그들은 다르다! iframe 태그를 작성하더라도 실제로 JS를 가져와야하고 이후에 YT.Player 객체를 만들어야합니다. 위 링크를보고 '동영상 플레이어로드'를 검색하십시오. ** API의 자바 스크립트 코드가로드 된 후 API는 onYouTubeIframeAPIReady 함수 ** –