无法在iOS 4中播放video

我已经编写代码在iPhone OS 3.1.3中播放video,video播放良好。

但是当我试图用相同的代码播放video,然后video不在iOS 4中播放。

我知道iOS 4的媒体播放器框架已更改。有没有什么办法可以在不同的操作系统上播放video而无需准备单独的二进制文件?

首先检查你是否在OS 3.2或以上。 如果是的话,以新的方式创build一个电影播放器​​:

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]; } 

你可以像这样closures新的电影播放器​​:

 -(void)videoPlayBackDidFinish:(NSNotification*)notification { [self dismissMoviePlayerViewControllerAnimated]; }