2016-09-21 2 views
0

iframe에 Youtube 비디오가 포함 된 페이지가 있습니다. 누군가 비디오를 재생할 때마다 비디오를 전체 화면으로 설정하려고합니다. 많은 것을 시도했지만 제대로 작동하지 않는 것 같습니다.Play 유튜브 iframe 전체 화면

내 코드 :

<div class="video-wrapper"> 
    <div class="video"> 
     <iframe id="home-video" allowfullscreen="allowfullscreen"  mozallowfullscreen="mozallowfullscreen" 
             msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" 
             webkitallowfullscreen="webkitallowfullscreen" frameborder="0" 
             src="https://www.youtube.com/watch_popup?v=dQw4w9WgXcQ"> 
     </iframe> 
    </div> 
</div> 

나는 또한 유튜브 API를 사용하여 이러한 목표를 달성하기 위해 노력했지만 성공하지.

<script src="https://www.youtube.com/iframe_api"></script> 

누구나?

답변

0

나는 HTML5에 대한 fullScreen API 시도 할 것이다 :

function fullScreen() { 

    var e = document.getElementById("video-wrapper"); 
    if (e.requestFullscreen) { 
     e.requestFullscreen(); 
    } else if (e.webkitRequestFullscreen) { 
     e.webkitRequestFullscreen(); 
    } else if (e.mozRequestFullScreen) { 
     e.mozRequestFullScreen(); 
    } else if (e.msRequestFullscreen) { 
     e.msRequestFullscreen(); 
    } 
} 

function YTStateChange(event) { 
    switch(event.data) { 
     case -1: 
      fullScreen(); 
     break; 
     case 1: 
      // some code 
     break; 
     case 2: 
      // some code 
     break; 
     default: 
     break; 
    } 
} 

$(document).ready(function() { 
    var player = new YT.Player('video-wrapper', { 
     events: { 'onStateChange': YTStateChange } 
    }); 
}); 
+0

대응을위한 Thx! 누군가 비디오를 시작할 때마다 비디오를 전체 화면으로 설정하려고합니다. 이 방법은 "다른"버튼을 클릭 할 때만 비디오 전체 화면을 설정합니다. 내가 찾는 방법이 아닙니다. –

+0

OK - 이것을 편집합니다 –

+0

event.data -1은 전체 화면이 아니라 "시작되지 않음"을 의미합니다. 모든 가능한 옵션을 보려면 YT.PlayerState를보십시오. "전체 화면"상태가 없습니다. –

0

을 유튜브 iframe이 API를 사용하고 설정 플레이어 이벤트를 수신하기 : https://developers.google.com/youtube/iframe_api_reference

당신이 플레이 이벤트가 전체 화면 함수를 호출 일단

  function launchIntoFullscreen(element) { 
       if(element.requestFullscreen) { 
       element.requestFullscreen(); 
       } else if(element.mozRequestFullScreen) { 
       element.mozRequestFullScreen(); 
       } else if(element.webkitRequestFullscreen) { 
       element.webkitRequestFullscreen(); 
       } else if(element.msRequestFullscreen) { 
       element.msRequestFullscreen(); 
       } 
      } 

      function onPlayerStateChange(event) { 
       if (event.data == YT.PlayerState.PLAYING) { 
       launchIntoFullscreen(YOURIFRAME) 
       } 
      } 
관련 문제