15

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.

SetBlue
  • 151
  • 1
  • 1
  • 3

9 Answers9

22

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

rcw3
  • 3,034
  • 1
  • 27
  • 24
9

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;


}
Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
2

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

Agat
  • 4,577
  • 2
  • 34
  • 62
  • Pretty sad news... I did not notice first, but that appears that when we hide everything on the movie playing, then status bar does not appear on the movie closing. That's obviously some bug in iOS, as it must not disappear, as I don't do anything related to it directly... and it appears after that when I open some modal controller, for instance, which, possibly, "refreshes" app context or something. Anyway... to make the status bar still appear, I just catch the last moment when movie finishes and do moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; – Agat Nov 10 '12 at 11:38
  • I also have to stop the video manually [moviePlayerController.moviePlayer stop]; after dismissing the movie controller also manually, otherwise I either have black screen left or video sound plays in the background when the controller is already disappeared. So, pretty "funny" behaviour of iOS. The moment how do I catch the video "will finish" is described here: http://stackoverflow.com/a/13318267/691660. Good luck to all of us! ) – Agat Nov 10 '12 at 11:39
1

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];
Juan de la Torre
  • 1,297
  • 9
  • 19
1

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];
}
Jing
  • 303
  • 1
  • 3
  • 11
0

I had the same problem but I added to my info.plist row Status bar is initially hidden - Boolean - YES and it works!
BTW I'm using iOS 5.1, Xcode 4.3.2.

martin
  • 93,354
  • 25
  • 191
  • 226
  • This will work unless you want the status bar for your app, just not for the movie. – Cthutu May 24 '12 at 14:57
  • 1
    I have `Status bar is initially hidden` set to `YES` (OpenGL ES app), yet the status bar appears when I present a `MPMoviePlayerController ` modally. – Nicolas Miari Jan 08 '13 at 06:56
  • I have Status bar hidden set to YES as well and I still get a status bar. The answer by rcw3 is correct, if you are using fullscreen controls, you can't hide the status bar. – Joshua Dance Mar 04 '13 at 23:54
0

I don't know if my solution applies to your issue, but it works for my setup, i.e. 4th gen ipod running iOS 5.1.

My applications does not show the status bar at all, and in the info.plist file the corresponding entry "Status bar is initially hidden" is set to YES.

I also directly add the MPMoviePlayerController view to its parent view. Here is the code to setup the movie player:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:frame]; // This is set to (0, 0, 320, 480)
[moviePlayer prepareToPlay];
[moviePlayer setShouldAutoplay:YES]; 
moviePlayer.fullscreen = TRUE;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self.view addSubview:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 

The moviePlayer is a class variable.

When the player finishes playing or when the viewer presses the "Done" button of the moviePlayer controller, the playbackFinished: method is called:

- (void)playBackFinished:(NSNotification *)notif{
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer release];
moviePlayer = nil;
}

In which the control style of the moviePlayer is set to MPMovieControlStyleNone to prevent any controls, but essentially the status bar from showing up when the moviePlayer is removed from its parent view.

Don Miguel
  • 882
  • 9
  • 19
0

this is not an answer, I am having the same issue. There is one part I can update however..

The status bar only shows when the controls show.

Clicking on the movie, hides the conrols & the status bar, clicking again, shows the controls, and the status bar comes back too.

I am also hiding the status bar programmatically just before I launch the movie.

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

and here is how I am adding the movie:

[[[UIApplication sharedApplication] keyWindow] addSubview: movieView];

nycynik
  • 7,371
  • 8
  • 62
  • 87
0

For those that have been running into this issue, I've found a solution of my own that might help. It only applies though if the rest of your app does not show the status bar and if you are trying to hide it again once the movie is done and returning to your interface, instead of during playback.

If your MPMoviePlayerController is being added as a subview to a UIView that is being pushed onto a navigation controller view stack, you can use that parent view controller's viewWillDisappear method to help you out.

In that method, you can change the control style to none, which will clear out any and all movie player controls before the view disappears and clears the status bar out as well if you already had it set to hidden. This will be completely unapparent to the user as the view is moving off screen and they are no longer interacting with it.