views:

364

answers:

3

Hi everyone,

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.

A: 

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;


}
unforgiven
A: 

Thanks for your answer but it doesn't work. Here's the code I used :

    -(void)launchVideoFromButton:(id)sender{

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

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

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


    //Present
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

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

    //

}



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

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

}

Unfortunately, it doesn't solve my problem. The moviePlayerEvent method is still fired and the NSLog it contains says '1' in the console. This should mean the statusBarHidden property is set to YES, but this status bar is still present on the screen.

I'm beginning to think there's no way to solve this issue :/

SetBlue
This is really weird, since in my case I do not see the status bar. Did you try without hiding yourself the status bar programmatically in your moviePlayerEvent method? Also try using the MPMoviePlayerPlaybackDidFinishNotification notification in place of MPMoviePlayerLoadStateDidChangeNotification.
unforgiven
A: 

Did you ever get this figured out?

I tried rotating the UI with a transform, and setting the status bar to landscape. This does work, but the MPMoviePlayerController will respond to rotation events and place the status bar back.

Broonix