开发者

MPMoviePlayerController can exit fullscreen but topbar is gone

I am streaming a movie on the iPad using MPMoviePlayerController.

When the user rotates the device to landscape, I animate it to fullscreen.

If the user then taps 'exit fullscreen' or 'done', the movie animates back to its small frame (native behavior), BUT-- the top bar (navigation bar) is gone. Also, the visible views ha开发者_C百科ve moved upwards, behind and beyond the status bar.

Note that I haven't touched the top bar whatsoever. I have not manually hidden it.

I have tried regaining the navigation bar by sending setNavigationBarHidden:animated to the current viewcontroller's navigation controller, as well as to the tabbarcontroller's navigationcontroller. I put this in response to the MPMoviePlayerDidExitFullscreenNotification (it fires). No effect. If we rotate back to portrait, however, it's back instantly.

My questions are:

  • Why does the top bar not return when full screen is exited by the user?
  • How can we get the top bar back?

Best regards, Timo

P.S. I will proceed to experiment with the weirdnesses described in this SO post. Might be related.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜