views:

321

answers:

1

I have written code to play video in iPhone OS 3.1.3 and video is playing fine.

but when i am trying to play video with the same code then video is not playing in iOS 4.

I know that Media player framework is changed for iOS 4. Is there any way i can play the video on different OS without preparing separate binary??

Thanks,
Jim.

+3  A: 

First check if you are on OS 3.2 or above. If yes, create a movie player the new way:

if (NSClassFromString(@"UISplitViewController") != nil) {
  MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:yourURL];
  [[mp moviePlayer] prepareToPlay];
  [[mp moviePlayer] setShouldAutoplay:YES];
  [[mp moviePlayer] setControlStyle:2];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
  [self presentMoviePlayerViewControllerAnimated:mp];
} else {
  moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:yourURL];
  [self playMovieTheOldWay:moviePlayer];
}

You can close the new movie player like this:

-(void)videoPlayBackDidFinish:(NSNotification*)notification
{       
  [self dismissMoviePlayerViewControllerAnimated];
}
Juri Keller
Thanks for reply. with which sdk i will have to compile the application in this case??
Jim
The "new media player" came with 3.2 so you need 3.2 or above to compile this. You cannot use the new media player with an old sdk.
Juri Keller
If i am compiling the application against the SDK 3.2 and later then will this application run on 3.1.3 or not??
Jim
If you set the deployment target to 3.1, it will work, even if linked and built with 4.0 (only new methods won't work - like movieplayerviewcontroller, which doesn't exists prior to 3.2).
Juri Keller
Thanks i am able to run application with above implementation on OS 3.1.3 and OS 4.0.Really appreciate your help.
Jim