Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide StatusBar from MPMoviePlayerController

I've been struggling with a very annoying problem all day long and I hope I could find help on this board.

I'm using an MPMoviePlayerController to play a fullscreen movie on iPad and I can't figure how to remove the status bar which is always displayed despite all my efforts to make it go to hell.

Here is the code of the method I use to display the movie :

-(void)launchVideoFromButton:(id)sender{

         NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"movie01" ofType:@"m4v"];
         NSURL *videoPathURL = [NSURL fileURLWithPath:videoPath];
         moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoPathURL];

         [self.view addSubview:moviePlayer.view];

         moviePlayer.shouldAutoplay = YES;
         moviePlayer.movieSourceType = MPMovieSourceTypeFile;


         [moviePlayer setFullscreen:YES animated:YES];
         moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

         NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
         [notificationCenter addObserver:self selector:@selector(moviePlayerEvent:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];

    }



    -(void)moviePlayerEvent:(NSNotification*)aNotification{

         [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
         NSLog(@"%i", [UIApplication sharedApplication].statusBarHidden);

    }

In the console, I can see that moviePlayerEvent is fired when the movie appears but the statusbar is still there : [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO] seems to be inoperant. I've been trying to use the other MPMoviePlayerController notifications with no luck.

Could anyone help me on that one?

Thanks in advance.

like image 439
SetBlue Avatar asked Sep 06 '10 17:09

SetBlue


3 Answers

Unfortunately, after running into this very problem, through research and much experimentation, I've determined that it is pretty much impossible to keep the iOS status bar hidden in full screen mode. No matter what you do, when the full screen player controls are shown, so will the status bar (it will not respect the setStatusBarHidden:YES). This is not the case with the embedded player controls, but the user can easily switch between embedded and full screen modes, so you can't really use this to maintain no status bar when the controls are shown.

Of course, at least the status bar goes away when the controls fade out...

like image 58
rcw3 Avatar answered Nov 05 '22 16:11

rcw3


Do not add the movie player's view to your main view; instead, present the movie player modally as follows (some steps omitted for brevity/clarity):

moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

// Register for the playback finished notification.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMovieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerViewController.moviePlayer];


//Present
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

    // Play the movie!
    self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [self.moviePlayerViewController.moviePlayer play];



// When the movie is done, release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{

    //NSLog(@"playback terminated");

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerViewController.moviePlayer];


    [moviePlayerViewController release], moviePlayerViewController = nil;


}
like image 27
Massimo Cafaro Avatar answered Nov 05 '22 14:11

Massimo Cafaro


It worked for me to use MPMoviePlayerViewController, setting up the following

[moviePlayerController.moviePlayer setFullscreen:YES animated:NO];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

before this:

[self presentViewController:moviePlayerController animated:NO completion:^{ }];

and the following right after:

moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;

just in case, I also did this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerLoadStateDidChange:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

...


- (void)moviePlayerLoadStateDidChange:(NSNotification *)notification {


    if ([[moviePlayerController moviePlayer] loadState] == MPMovieLoadStateStalled) {

    } else if([[moviePlayerController moviePlayer] loadState] != MPMovieLoadStateUnknown) {

        [moviePlayerController moviePlayer].controlStyle = MPMovieControlStyleNone;

        ...
    }
}

So, no status bars, no controls... nothing but only a pure video. )

(Tested on iOS 5.1 device and 6.0 simulator).

like image 2
Agat Avatar answered Nov 05 '22 15:11

Agat