开发者

MPMoviePlayerController fullscreen movie inside a UIWebView

开发者 https://www.devze.com 2022-12-28 12:05 出处:网络
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 h开发者_如何学编程tml5 and a video tag for the vid

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 h开发者_如何学编程tml5 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


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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号