转到第二个 UIViewController 时无法保存或查看视频



我有一个UIViewController,我使用GPUImage创建视频。现在,当创建视频时,我将NSURL传递到第二个UIViewController,在那里我向我们显示了一个AVPlayerViewController

通过以下方式显示

- (void)showTheVideo {
/// ----------
/// Show the video
/// ----------

// grab a local URL to our video
NSURL *videoURL = self.completeMovieURL;
// create an AVPlayer
self.player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = self.player;
[controller setShowsPlaybackControls:TRUE];
[controller.view setBackgroundColor:[UIColor clearColor]];
//controller.videoGravity = AVLayerVideoGravityResizeAspectFill;

// show the view controller
[self addChildViewController:controller];
[self.viewVideo addSubview:controller.view];
controller.view.frame = self.viewVideo.frame;
[self.player play];
}

问题是第二个UIView控制器上的播放确实是命中和未命中。有时它会加载视频,有时不会。我已经检查了self.completeMovieURL,路径在那里。

现在为了测试视频是否实际创建,我尝试使用

[PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:self.completeMovieURL];

但是我收到一个错误,但是如果我尝试将其保存在我创建的视图控制器上,则可以保存正常。

有人可以解释为什么我可以将视频保存在第一个控制器上,但不能保存在第二个控制器上并且播放时遇到问题吗?

使用以下代码保存视频:

#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetsLibrary.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
- (void)writeToAlbum:(NSURL *)outputFileURL{
self.library = [[ALAssetsLibrary alloc] init];
if ([_library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL])
{
[_library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
completionBlock:^(NSURL *assetURL, NSError *error)
{
if (error)
{
dispatch_async(dispatch_get_main_queue(), ^{
//  [SVProgressHUD showErrorWithStatus:@"failed"];
});
NSLog(@"fail to saved: %@", error);
}else{
NSLog(@"saved");
dispatch_async(dispatch_get_main_queue(), ^{
//  [SVProgressHUD showSuccessWithStatus:@"saved"];
});
}
}];
}}

最新更新