Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

youtube javascript API detect fullscreen exit on iOS devices

I can't seem to figure out which element should I add the event listener to for it to work on iOS, I'm listening to these events

['webkitfullscreenchange', 'mozfullscreenchange', 'fullscreenchange', 'MSFullscreenChange']; 

and listening on both document and the element you pass to new YT.Player(), both are firing just fine on desktop browsers as well as android browsers, but neither fires on iOS (chrome or safari, doesn't matter).

You can check it live here, at the bottom http://youtubeplayer.fxck.cz/ -1, 1, 2, 3 are the standard youtube player events, 1337 is fullscreenchange from the element, 1338 is fullscreenchange from document.

like image 801
fxck Avatar asked Dec 02 '17 13:12

fxck


People also ask

Why can't I take a fullscreen video on iOS?

Oh, actually, I think I figured out what the issue was. iOS doesn't support the fullscreen API and it only lets the native video element be taken fullscreen with the native controls, which is what enterFullscreenon the tech does.

Is it possible to make videojs fullscreen?

If the tech implements supportsFullscreen, videojs will try and enter "full window" mode where it just makes the player div take over the entire screen, kind of faking fullscreen. But otherwise, unless a native video element is being used, I don't think you'd be able to go fullscreen.

How do I run a JavaScript code sample in the APIs explorer?

The APIs Explorer uses demo credentials by default to make it easier to get started. But you'll use your own API key to run the sample locally. The right side of the fullscreen APIs Explorer shows tabs with code samples in different languages. Select the JavaScripttab.

How do I use the API's JavaScript functions?

Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played. You can also add event listeners that will execute in response to certain player events, such as a player state change.


Video Answer


1 Answers

use the following detection ways:

document.onwebkitfullscreenchange
document.onfullscreenchange
document.onmozfullscreenchange

also use a variable to store whether or not fullscreen was entered

isInFullscreen = false;

the moment one of those above get called we just negate the current state. that way we detect fullscreen changes.

jquery approach example:

 var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
  $(document).on ('mozfullscreenchange webkitfullscreenchange fullscreenchange',function(){
      isFullscreen = !isFullscreen;
  });

you will need to have more indicators to ensure compability with every browser out there.

like image 55
Snackaholic Avatar answered Sep 30 '22 18:09

Snackaholic