我正在使用GPUImage
库将视频录制到文件系统上的文件中。我将其保存为 m4v 文件。这是我正在使用的代码:
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:recordingDestination];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1280.0, 720.0)];
[videoCameraFilter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];
[movieWriter setCompletionBlock:^{
[videoCameraFilter removeTarget:movieWriter];
[movieWriter finishRecording];
}];
这会录制一个 m4v 视频。然后我尝试玩它MPMoviePlayerController
:
NSString *videoPath = [NSString stringWithFormat:@"%@/%@", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], [libraryFiles objectAtIndex:selectedCell]];
NSLog(videoPath);
NSURL *url=[[NSURL alloc] initWithString:videoPath];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
但是,播放器只是开始缓冲,没有任何反应。视频没有开始播放。玩家只是永远在缓冲。该应用程序没有崩溃,控制台中也没有警告,所以我不知道是什么问题。