Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerViewController Hide Status Bar

I have an iPad application that creates and shows a video with an MPMoviePlayerViewController. Here's my code:

MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:URLEncode(uri)]];
[mpvc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[mpvc setWantsFullScreenLayout:YES];
[<MainViewController> presentModalViewController:mpvc animated:YES];

Movie load/playback works fine, however, when the Movie Controller appears, it shows the status bar (connection, battery, hour) at the top, even when I have it deactivated on my main window.

I've tried doing:

[mpvc setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

And nothing seems to work, HOWEVER if I also put:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

The status bar disappears! But the Movie Controller still gets resized as if the status bar is there (even when I already used -setWantsFullScreenLayout:).

Can someone point me to an easy (proven) way to show the video without the status bar?

Thanks.

like image 385
Ale Morales Avatar asked Sep 15 '10 19:09

Ale Morales


1 Answers

Just realised the question was iPad-specific. My code was for the iPhone, but some of it may help you anyway.

I had to do this a couple days ago, I think your issue is simply not calling hide on the status bar after the video starts playing. Either way I have the tried and tested code here which works from 3.0 to 4.2:

- (IBAction) playIntroVideo
{
    NSString *videoString = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mp4"];
    NSURL *videoURL = [NSURL fileURLWithPath:videoString];
    _player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

    if
    (
        [_player respondsToSelector:@selector(view)] &&
        [_player respondsToSelector:@selector(setFullscreen:animated:)] &&
        [_player respondsToSelector:@selector(setControlStyle:)]
    )
    {
        [[_player view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT_FULL)];
        [_player setFullscreen:YES animated:YES];
        [_player setControlStyle:MPMovieControlStyleNone];
        [self.view addSubview:[_player view]];
    }

    [_player play];

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(terminateVideo)
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:nil];   

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.navigationController.navigationBarHidden = YES;
}

- (void) terminateVideo
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    self.navigationController.navigationBarHidden = NO;

    if ([_player respondsToSelector:@selector(view)])
    {
        [[_player view] removeFromSuperview];   
    }

    _player = nil;
    [_player release];
}
like image 136
Simon Avatar answered Sep 28 '22 08:09

Simon