- (void)assetsPickerController:(GMImagePickerController *)picker didSelectAsset:(PHAsset *)asset{
self.videoURL = [NSURL URLWithString:asset.localIdentifier];
NSLog(@"The value of URL is %@:",self.videoURL);
[self playVideo];
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)playVideo{
self.playerVC = [[MPMoviePlayerViewController alloc] init];
self.playerVC.moviePlayer.contentURL = self.videoURL;
self.playerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self.playerVC.moviePlayer.view setFrame:CGRectMake (0, 100, 320, 385)];
[self.view addSubview:self.playerVC.moviePlayer.view];
[self.playerVC.moviePlayer play];
}
从相机胶卷中选择视频后,我打算在应用上播放,但会出现黑屏,如下所示:
我的代码出了什么问题?谢谢!
答案 0 :(得分:1)
此处MPMoviePlayerViewController无法获取您的视频网址。您应该检查视频网址是否可用。 在这里,您将获得后台线程中的视频网址
[asset requestContentEditingInputWithOptions:kNilOptions
completionHandler: ^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
self.videoURL = contentEditingInput.fullSizeImageURL;
}];
直到获得视频网址,MPMoviePlayerViewController代码才会被执行。
要首先解决此问题,您应该获取视频网址,如果网址可用,请调用MPMoviePlayerViewController代码播放视频。