无法播放录制的视频 - iOS

时间:2014-02-08 10:12:07

标签: ios iphone objective-c xcode ios7

重要:我可以在iPhone图库中查看和播放此电影。

我开始在这里录制

AVCaptureMovieFileOutput *movieFileOutput;

NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[@"movie" stringByAppendingPathExtension:@"mov"]];

[movieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputFilePath] recordingDelegate:self];

几秒钟后我停止录音..

[movieFileOutput stopRecording];

然后我想播放我刚录制的电影。但我不能...... MPMoviePlayer屏幕出现并立即消失..

MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:outputFilePath]];


[self presentMoviePlayerViewControllerAnimated:mediaPlayer];

重要:我可以在iPhone图库中查看和播放此电影。

---------


日志:

outputFilePath Log:

2014-02-08 12:06:46.232 TestApp[3953:60b] VIDEO PATH URL : /private/var/mobile/Applications/71039166-5A6D-43BE-A47A-B20AA93D2F2A/tmp/movie.mov

消失后的MPMoviePlayer日志:

2014-02-08 12:06:47.431 TestApp[3953:60b] _itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
}

1 个答案:

答案 0 :(得分:0)

保存数据不是同步的:手机可能需要一些时间才能完成在输出文件上写入数据。

尝试将presentMoviePlayerViewControllerAnimated:mediaPlayer:置于回调captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:内,当手机完成保存视频时调用该回调{{3}}。

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
    MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:outputFilePath]];

    [self presentMoviePlayerViewControllerAnimated:mediaPlayer];
}