开发者

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 setModa开发者_如何学ClTransitionStyle: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.


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];
}


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜