播放MOV文件的最佳方式是什么?

时间:2012-11-05 14:36:42

标签: ios

我已经从UI的屏幕截图生成了MOV文件并录制了声音。结合视频和音频并生成MOV格式的电影。

我看过很多MPMoviePlayerViewController示例,但它只是显示我的黑屏。我试过AVPlayer,但我无法让它工作。

我是在iOS上播放电影文件的新手,请帮忙。

这是我的代码:

NSString  *fileNamePath = mVideo;
NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths  objectAtIndex:0];
NSString  *oldappSettingsPath = [documentsDirectory stringByAppendingPathComponent:fileNamePath];
NSURL *path = [NSURL fileURLWithPath:oldappSettingsPath];
self.mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:path];

self.mPlayer.controlStyle = MPMovieControlStyleFullscreen;
self.mPlayer.fullscreen = YES;
self.mPlayer.scalingMode = MPMovieScalingModeFill;
[[self.mPlayer view] setFrame: CGRectMake(0, 0, 480, 320)];
[self.view addSubview:[self.mPlayer view]];
[self.mPlayer prepareToPlay];
[self.mPlayer play];

1 个答案:

答案 0 :(得分:2)

我发现修复了MPMoviePlayerController

         NSURL *path = [NSURL fileURLWithPath:oldappSettingsPath];
         if ([[NSFileManager defaultManager] fileExistsAtPath:oldappSettingsPath]) {
             NSLog(@"Exist");
             self.mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:path];
             self.mPlayer.movieSourceType = MPMovieSourceTypeFile;
             self.mPlayer.controlStyle = MPMovieControlStyleFullscreen;
             self.mPlayer.fullscreen = YES;
             self.mPlayer.scalingMode = MPMovieScalingModeFill;
             [[self.mPlayer view] setFrame: CGRectMake(0, 0, 480, 320)];
             [self.view addSubview:[self.mPlayer view]];
             [self.mPlayer prepareToPlay];
             [self.mPlayer play];
         } else {
             NSLog(@"Don't Exist");
         }

我还补充道:

        self.mPlayer.movieSourceType = MPMovieSourceTypeFile;

在我的情况下,播放器显示黑屏,因为我播放的文件不存在,所以如果文件存在与否,我首先添加一个检查。