开发者

Better way to make MPMoviePlayer with Overlay view

When we creating application with MPMoviePlayer (within custom UIViewController) and with overlay UIViewController on top of movie player what is better: - Load movie in player with self.view.presentMod开发者_运维百科alView... or self.view.addSubView... Or is there any other better way. I now work with modal views and everything works except I have to implement some custom rotations. I am looking for more clear way to make this.

Ok maybe some more details. In iPhone app I add player like modal view and add overlay view to it and that works. But this is universal app and it doesn't work on iPad the same way it works on iPhone. In ipad splitView my player is on details side (nonfullscreen), when I double tap player it goes fullscreen. And now player is key window. Here is the biggest issue. I tried to add overlay view as subviw and modal view and I made it but that overlay is not aware of device orientation, and I have to transform overlay elements and this is what I am trying to avoid. Is there any way to detect rotation on that view?


Simple and most elegant solution:

Do not use the "real" fullscreen mode but scale the MPMoviePlayerController's view towards a screen-filling size - MPMoviePlayerController.view.frame = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f);. Keep the MPMoviePlayerController's view on top of a regular UIViewController's view that allows rotations (addSubview). Keep your custom interface view on top of the MPMoviePlayerController's view (addSubview) and presto, you will get a properly rotating video player no matter if you run it in "fullscreen" or not.


I found one solution but I am not very proud because I this that there is some better way, but this workaround works: - In project I have on singleton class that contains some global data for me. - When application start in detail view (UISplitView) willAnimateRotationToInterfaceOrientation method is called first. Here I get current orientation and store it in singleton class. - Later when I add overlay on top of player I read data from singleton and transform overlay elements.


According to above I did something like this:

mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];

mp.movieSourceType = MPMovieSourceTypeStreaming;

mp.view.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);

[self.view addSubview:mp.view];

mp.controlStyle = MPMovieControlStyleNone;

[self.view addSubview:self.myOverlay];


[mp play];

Actually it was so easy! Just choose control style to None and add your low opacity view on the player view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜