Hide StatusBar from MPMoviePlayerController

19,518

Solution 1

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...

Solution 2

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;


}

Solution 3

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).

Solution 4

The status bar did hided, but showing up again with the play control.

  -(void)viewDidLoad:{
        [super viewDidLoad];
        MPMoviePlayerViewController *moviePlayerViewController =
                [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

        [[NSNotificationCenter defaultCenter] addObserver:self 
                 selector:@selector(playbackStateChange:)
                 name:MPMoviePlayerLoadStateDidChangeNotification
                 object:moviePlayerViewController.moviePlayer];
    }
    -(void)playbackStateChange:(NSNotification*)notification{
        if([[UIApplication sharedApplication]respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
        [[UIApplication sharedApplication] setStatusBarHidden:YES 
                       withAnimation:UIStatusBarAnimationNone];
        else 
            [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
}

Solution 5

Using MPMovieControlModeVolumeHidden didn't work for me, the only one that worked was MPMovieControlModeVolumeOnly with the video in fullscreen:

myMoviePlayer.controlStyle = MPMovieControlModeVolumeOnly;
[myMoviePlayer setFullscreen:YES];

And also, I am adding the movie view as a subview to the parent view:

[parentView addSubview:myMoviePlayer.view];

My app is supposed to not have status bar and for backwards compatibility I use the following code on the app delegate:

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
else
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
Share:
19,518
SetBlue
Author by

SetBlue

Updated on July 18, 2022

Comments

  • SetBlue
    SetBlue almost 2 years

    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.