我正在使用 MPMoviePlayerController 播放“.3gp”视频,我从服务器获取数据并将其保存在 NSData 对象中,然后将其写入 Document 目录中的文件这是我的代码
在 .hi 中将 videoPlayer 定义为
@interface MainViewController : UIViewController {
MPMoviePlayerController* videoPlayer; }
@property (strong, nonatomic) MPMoviePlayerController* videoPlayer;
在 .m 文件中
-(void)videoWillStartPlayWithUrl:(NSData *)d
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.3gp"];
[d writeToFile:path atomically:YES];
NSURL *url = [NSURL fileURLWithPath:path];
adBannerView.hidden = YES;
self.videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded;
self.videoPlayer.shouldAutoplay = YES;
[self.videoPlayer.view setFrame: self.view.bounds];
[self.view addSubview:self.videoPlayer.view];
[self.videoPlayer setFullscreen:YES animated:YES];
[self.videoPlayer prepareToPlay];
[self.videoPlayer play];
}
它在 iOS < 5 中完美运行,但在 iOS 5 中它只是显示黑屏并直接退出 ,我似乎无法解决阻止视频在 iOS 5 中播放的问题,非常感谢任何帮助