How to capture a fullscreen event when I click the default fullscreen button for an HTML5 video element?

I have a problem using the HTML5 videoand tag iconic.

Here is part of my template:

<ion-view>
   <ion-content overflow-scroll="true" data-tap-disable="true">
      <div class="list card">
        <div class="item item-body" style="padding: 5% 5% 5% 5%">
            <div class="player">
            <video controls="controls" autoplay id="sr"></video>
          </div>
        </div>
      </div>
   </ion-content>
</ion-view>

Here is my controller:

.controller('viewVideoCtrl', function ($scope, $state, $stateParams) {
   var videoPath = URL + "uploadFiles" + $stateParams.videoPath;

   var videoObject = document.getElementById("sr");
   videoObject.src = videoPath;
   var webkitBeginFullScreen = function () {
      alert("video has fullScreen!");
   };

   var onVideoEndsFullScreen = function () {
     alert("fullScreen has end!");
   };

   videoObject.addEventListener('webkitbeginfullscreen', webkitBeginFullScreen, false);
   videoObject.addEventListener('webkitendfullscreen', onVideoEndsFullScreen, false);
});

As you can see, there is no custom tag control button videoand use the default control panel, which is created by chrome itself.

Now I want to do something when the button is pressed fullscreen. I found a solution that adds two listeners: webkitbeginfullscreenand webkitendfullscreento the video object, but it does not start.

+4
source share
1 answer

Android iOS, <video> :

  • webkitfullscreenchange
  • mozfullscreenchange
  • fullscreenchange

, , .

:

function onFullScreen(e) {
  var isFullscreenNow = document.webkitFullscreenElement !== null
  alert('Fullscreen ' + isFullscreenNow)
}

document.getElementById("video").addEventListener('webkitfullscreenchange', onFullScreen)
+2

Source: https://habr.com/ru/post/1625100/


All Articles