tags:

views:

153

answers:

1

In iOS4 for iPhone 4/3GS, I have a tableview and one of the cells plays back a movie file. If the movie finishes playing back and the controls have disappeared the view comes back in under the status bar. Like in this image...that I'm too new to post. See it here...

http://www.dezignwright.com/ios4_movie.png

If the controls are on when the movie finishes, then there is no problem.

BONUS: How do I force the movie player into landscape when it starts playing. I don't want it to play in portrait at all.

Thanks.

A: 

This appears to be a bug in 4.0, it works correctly when exiting using the "Done" button.

The workaround I use is to manually store the frame then restore it when receiving the MPMoviePlayerPlaybackDidFinishNotification.

Finally to get it in landscape mode, use a subclass of MPMoviePlayerViewController where you override shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

I.e. something like this:

@interface CustomMoviePlayerViewController : MPMoviePlayerViewController
@end
@implementation CustomMoviePlayerViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
@end

And in your controller to work around the bug:

- (void)playbackEnded:(NSNotification *)notification
{
    [[self view] setFrame:[self originalFrame]];
}

- (void)playMovie:(NSString *)movieURLString
{
    MPMoviePlayerViewController *controller = [[CustomMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURLString]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackEnded:) name:MPMoviePlayerPlaybackDidFinishNotification object:[controller moviePlayer]];
    [self presentMoviePlayerViewControllerAnimated:controller];
}
Nuoji
Thanks!!! I'll give it a try.
Tom Zmyslo
Did it work for you?
Nuoji