Since 3.2 iPhone OS SDK, playing a video is really different.
So I was wondering if there is a way to make video play in full screen with a compatible code (both < and >3.2) without writing code for the two cases.
I think we'll have to write 2 versions of our classes handling video playing...
Thy !
I do basically what Jeff Kelly above suggests to run on 3.1 and above, note the instancesRespondToSelector call:
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
//Will only run this code for >= OS 3.2
if ([MPMoviePlayerController instancesRespondToSelector:@selector(setFullscreen:animated:)]){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(nowPlayingMovieDidChange:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
mp.controlStyle = MPMovieControlStyleFullscreen;
[mp setScalingMode:MPMovieScalingModeAspectFit];
//change mainMenu here to whatever your parent view is
[mp.view setFrame:mainMenu.frame];
[self.view addSubview:mp.view];
[mp setFullscreen:YES animated:NO];
}
//continue as normal
and then later in the moviePlayBackDidFinish function I use the same technique to remove the notifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With