YouTube iframe player - trigger fullscreen on iOS
Asked Answered
B

3

12

Using the YouTube iframe embed player, is there a way to trigger fullscreen programatically? I want to remove the default controls (using controls=0) but then have the ability to create custom fullscreen button by itself.

Brie answered 11/9, 2012 at 2:12 Comment(1)
You may try and look into UIWebView child views for a AVPlayer class , and put its layer to full screenElation
N
4

Make the iframe not fullscreen but fullpage:

    function fullscreen() {
        var vid = document.getElementById("vid");
        vid.style.position = "absolute";
        vid.style.width = "100vw";
        vid.style.height = "100vh";
        vid.style.top = "0px";
        vid.style.left = "0px";
        document.getElementById("exit").style.display = "inline";
    }
    function exitfullscreen() {
      var vid = document.getElementById("vid");
      vid.style.position = "";
      vid.style.width = "";
      vid.style.height = "";
      vid.style.top = "";
      vid.style.left = "";
      document.getElementById("exit").style.display = "none";
    }
<iframe width="560" height="315" src="https://www.youtube.com/embed/fq6qcvfZldE?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" id="vid" allowfullscreen></iframe>
    <button onClick="fullscreen()">Fullscreen</button>
    <button style="position: fixed; 
                   bottom: 5px; 
                   right: 5px; 
                   display: none;
                   z-index: 2000;" id="exit" onClick="exitfullscreen()">Exit Fullscreen</button>

The full page button in the right upper corner of the code snippet also works this way. If you want to make the browser full screen you could try document.requestFullscreen();, but this is still experimental and works on very few browsers. Take a look at the MDN topic of this function.

EDIT: Just found this: https://developers.google.com/youtube/?csw=1#player_apis, the official youtube player API.

Nitroparaffin answered 9/5, 2015 at 16:5 Comment(0)
P
1

Try the following in Webkit browsers:

if (typeof iframe.webkitRequestFullScreen === 'function') {
    button.addEventListener('click', function () {
        iframe.webkitRequestFullScreen();
    }, false);
}

Note that this won't work without a user gesture (in this case, 'click').

Prestige answered 11/5, 2015 at 20:2 Comment(0)
G
0

You can use this library XCDYouTubeKit instead of iframe player.
Its very simple and powerful. Supports full-screen as well as non full-screen.

Garfish answered 28/12, 2015 at 10:56 Comment(2)
I don't see how this answers the questionSententious
Its dont :) its just an alternative solution of what he want to achieve (and probably is the fastest and easies way)Garfish

© 2022 - 2024 — McMap. All rights reserved.