/ iOS

Detect full screen status of video playback in WebView

Background

When you have a web view and the web view contains a video, then the video playback is controlled by web view instance. By default, the video playback support in-line and full screen.

in line video playback

full screen video playback

Problem

If you're still trying to support iOS6 or iOS7 at this moment, then you might face a problem related to the presenting ViewController's rotation status if your app supports more than one orientation.

  1. View controller A contains web view B
  2. Web view B displays a page with video inside
  3. User taps the video, and the video start to playback
  4. User taps the full screen button like
  5. User rotates the device in full screen
  6. User dismiss the video playback full screen
  7. User saw your presenting view controller A's layout is not updated

Solutions

The solution is to get the notification when video playback exits full screen. So far, we have 3 solutions.

In iOS8, the video playback view controller will present the video on top of your current view hierarchy, but, before iOS8, the video playback is presented as a model view controller

Use undocumented notifications

@"UIMoviePlayerControllerDidExitFullscreenNotification" is an undocumented notification emitted by UIWebView, similar to MPMoviePlayerControllerDidExitFullScreenNotification.

This works perfect because this notification is dropped in iOS8, but comes with a risk that it might get rejected!

I haven't tested this in my app.

Use window related notifications

UIWindowDidBecomeVisibleNotification && UIWindowDidBecomeHiddenNotification are officially supported, but the thing is it will make your code more complicated, because the behaviour prior to iOS8 and from iOS8 are different.

Use Javascript

I don't like this solution, but yes, you can, because Mobile Safari will propagate webkitbeginfullscreen & webkitendfullscreen to video tag. To visit the detail, please take a look at this Stack Overflow page.