15

I'm having a problem with the UIWebView and MPMoviePlayerController: My UIWebView have a movie inside the html (it's a local html file), I'm using html5 and a video tag for the video. The problem is: the user can set the video to play inline, directly on the html or he can tap the fullscreen button, but I need to know if the video is playing fullscreen.

I've tried to use MPMoviePlayerDidEnterFullscreenNotification but with no success.

Does anybody know how to get this notification from the webview?

Thanks in advance

Wakazors
  • 151
  • 1
  • 3
  • See my answer on http://stackoverflow.com/questions/8518719/how-to-receive-nsnotifications-from-uiwebview-embedded-youtube-video-playback/8554040#8554040 for actually finding a way to accomplish this. – Till Jan 06 '12 at 20:19
  • This is the best solution I found and I worked for me http://stackoverflow.com/a/9088751/1002338 – Mona Oct 15 '12 at 22:39

4 Answers4

15

There is no notification being sent (also see this post: Event on view displayed change (Youtube MPMoviePlayerViewController)), but the web view will do something hackish: it will add a subview to the root UIViewController's view, make it full screen and play the movie there.

Make your main UIViewController's view a view of your own, and intercept -didAddSubview: and -willRemoveSubview:. This way you'll be able to detect when the player is brought fullscreen.

Community
  • 1
  • 1
fpillet
  • 281
  • 2
  • 6
  • That little comment about adding a subview to the root UIViewController's view was invaluable. Without it, I had no idea why my RootViewController's appearance methods were getting called, whenever I left a full screen movie player that was being hosted in a completely different VC. – Julian Jul 11 '13 at 08:08
4

You can also tag your main view and extend UIView (or implement the methods below in case you own the main view):

@implementation UIView (UIViewExtended)
- (void)didAddSubview:(UIView *)subview {
   if (subview.superview.tag == ... ) {
... set some flag here or do some action
   }
}

- (void)willRemoveSubview:(UIView *)subview {
   if (subview.superview.tag == ... ) {
... set some flag here or do some action
   }
}
@end
BojanG
  • 1,872
  • 1
  • 15
  • 23
Mila
  • 41
  • 1
2

If you are embedding your movie in a web view using HTML, then you'll need to address your movie using Javascript rather than the MPMoviePlayer class.

Take a look at Apple's scripting guide for Quicktime here.

I think the property you require is GetRectangle() which returns a string of the location and dimensions of the movie within the embed area.

Once you have the dimensions, you can pass it back into Objective-C from Javascript.

Mohsin Khubaib Ahmed
  • 1,008
  • 16
  • 32
  • This is helpful for telling what the size of the rectangle is at a given time; however, the question asks how to get the notification that the movie player has entered fullscreen (or that the size changed). – Josh Brown Nov 30 '10 at 07:22
0

From Apple's documentation:

Full-Screen Event and Properties

Safari emits a webkitfullscreenchange event when an element enters or exits full-screen mode. Listen for this event to detect changes.

You can test the document.webkitIsFullScreen property to see whether Safari has most recently entered or exited full-screen mode. The property is true when in full-screen mode.

The document.webkitCurrentFullScreenElement property contains the element that is in full-screen mode. Use this property if you have more than one element that could be in full-screen mode.

Unfortunately these don't appear to work on iOS. Apple needs to change this.

Community
  • 1
  • 1
Ben Jackson
  • 860
  • 8
  • 11