我使用 MPMoviePlayerViewController 播放格式为 3gp 的视频。有的视频可以播放,有的不能播放。MPMoviePlayerViewController 将立即加载并结束,就像视频是 0 秒持续时间一样。我认为视频一定有问题。但是我用的是相册里面的iphone的视频播放器,它可以播放视频!所以我认为 MPMoviePlayerViewController 可能并不强大。我想尝试使用 avfoundation 框架 avplayer 播放视频。在我的内容视图中添加一个子层。失败了..这让我发疯!有人遇到过一些问题吗?
这是我的代码
-(void) playMovieWithSDK: (NSURL*) movieUrl
{
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
MPMoviePlayerViewController *mSdk4Player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
mSdk4Player.navigationController.navigationBar.tag = 1000;
if (mSdk4Player) {
[self presentMoviePlayerViewControllerAnimated:mSdk4Player];
mSdk4Player.moviePlayer.scalingMode= MPMovieScalingModeAspectFit;
mSdk4Player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mSdk4Player.moviePlayer.shouldAutoplay = YES;
[mSdk4Player release];
[[NSNotificationCenter defaultCenter]addObserver: self
selector: @selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: mSdk4Player.moviePlayer];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) { // sdk 3.0 播放器
MPMoviePlayerController* mSdk3player = [[MPMoviePlayerController alloc] initWithContentURL: movieUrl];
mSdk3player.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter]addObserver: self
selector: @selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: mSdk3player];
[mSdk3player play];
}
}