MPMoviePlayerViewController Hide Status Bar
Asked Answered
V

3

14

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.

Valise answered 15/9, 2010 at 19:57 Comment(0)
C
2

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];
}
Coloratura answered 15/12, 2010 at 1:4 Comment(0)
I
0

The answer to this question has an error at the end:

_player = nil;
[_player release];

These should be reversed:

[_player release];
_player = nil;

Messaging nil with release has no effect.

Increase answered 14/1, 2011 at 18:57 Comment(0)
M
-3

You can set UIStatusBarHidden in your plist, that should solve it :)

Monroy answered 12/12, 2010 at 22:39 Comment(2)
UIStatusBarHidden. No, it doesn't help.Underplot
Hiding the status bar for the entire application just so it doesn't appear while a movie plays is not an appropriate solution.Dulcinea

© 2022 - 2024 — McMap. All rights reserved.