MPMoviePlayerController can exit fullscreen but topbar is gone

二次信任 提交于 2019-11-30 16:25:40

I just found a better way to to this (without the glitch when back from the view controller). Hiding the navigation bar when entering fullscreen and displaying it again on exit :

// In the view did load for example :
[[NSNotificationCenter defaultCenter] addObserver:self
     selector:@selector(moviePlayerWillExitFullScreen:) 
    name:MPMoviePlayerWillExitFullscreenNotification 
    object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidEnterFullScreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];

// And in the ViewController put these methods :
- (void) moviePlayerWillExitFullScreen:(id)sender {
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)moviePlayerDidEnterFullScreen:(id)sender {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

This will just be a bit more smooth in the animations.

Since this appears to be a bug in Apple's SDK (read post scriptum below), I have worked around it.

When you get the MPMoviePlayerDidExitFullscreenNotification, take the following steps:

  1. Send [setNavigationBarHidden:YES animated:NO] to the navigation bar.
  2. Send [setNavigationBarHidden:NO animated:YES] to the navigation bar.

There will be a slight glitch, namely the bar animating back down. Still, it's a lot better than your bar disappearing and the user left in wonder!

The animated:YES seems necessary to make the bar (re)set its position (rather than just its visibility).

You could try to make it appear instantly (animated:NO) after a 0 or 0.1 second delay using -performSelector:withObject:afterDelay:. You will probably still have to start the animation first, or the bar won't adjust its position.

Cheers, Timo

P.S. This appears to be a bug in the SDK. If you run, for example, the TED iPad application, you can reproduce it in there as well. The steps were something along the lines of: play a video, pinch to fullscreen, rotate iPad to landscape, press done. Experiment with it a bit and you should see the navigation bar disappear.

Yogi

The first assumption may be that the problem is with [MPMoviePlayerControler setFullScreen] and the same was mine. But after looking more carefully I came to know that the problem was with controls provided with MPMoviePlayerController(Play,Pause,Done etc.) by Apple. The mode of controls is set to Default controls by Apple. When we rotate the device the controls should be changed according to the new dimensions of the screen which doesn't happen. So, we should refresh the controls while rotating the device.

Following is the code which did the same for me:

//set the mode of controls before playing movie or when view loads
-(void) playMovie:(UIButton *)btn {      
    mpmpController.controlStyle=MPMovieControlStyleEmbedded;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toIO
                                duration:(NSTimeInterval)duration {
     //this sets the controls to None
     mpmpController.controlStyle=MPMovieControlStyleNone;    
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromIO {
    //reset the controlStyle
    mpmpController.controlStyle=MPMovieControlStyleEmbedded; 
}

This will do the task perfectly. At least it did it for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!