Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController fullscreen movie inside a UIWebView

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

like image 754
Wakazors Avatar asked Apr 27 '10 03:04

Wakazors


3 Answers

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.

like image 137
fpillet Avatar answered Nov 03 '22 01:11

fpillet


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
like image 35
Mila Avatar answered Nov 03 '22 00:11

Mila


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.

like image 2
Purpletoucan Avatar answered Nov 03 '22 01:11

Purpletoucan