- (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];
}
After choosing video from Camera Roll, I intend to play it on app but a black screen appears as shown:
What's wrong with my code? Thanks!
Here MPMoviePlayerViewController doesn't get your video url. You should check that video url is available or not. Here you are getting video url in background thread
[asset requestContentEditingInputWithOptions:kNilOptions completionHandler: ^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { self.videoURL = contentEditingInput.fullSizeImageURL; }];
Till you get video url, MPMoviePlayerViewController code get executed.
To overcome this issue first you should get video url and if url is available call MPMoviePlayerViewController code to play video.