Video disappearing when played after using UIImagePickerController in a UIPopoverController
I am having the toughest time playing a video after select anything from a UIImagePickerController when the UIImagePickerController is presented in a UIPopoverController.
Here is the code that presents the video:
-(void) presentMovie{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mov"];
NSURL *movieURL = [NSURL URLWithString:filePath];
[[mp moviePlayer] setContentURL:movieURL];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setShouldAutoplay:NO];
[[mp moviePlayer] setControlStyle:MPMovieControlStyleEmbedded];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[mp moviePlayer] setAllowsAirPlay:YES];
[[mp view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[screen addSubview:mp.view];
[[mp view] setFrame:screen.bounds];}
mp is a MPMoviePlayerViewController ivar that is allocated and initialized in my viewDidLoad
[self presentMovie] works perfectly unless it is being called from within the -imagePickerController:didFinishPickingMediaWithInfo: method
When called from that delegate methode, the video being displayed by MPMoviePlayerVideoController simply disappears from as soon as it is played. If the 'shouldAutoPlay' property is set to YES, I just see loading for a split second and then blackness. If the 'shouldAutoPlay' property is set to NO, then I see the first frame of the video, and I can scrub to a different location in the vido, take the video in and out of full screen, etc. but soon as I hit play, the view that the 开发者_JAVA技巧video is in goes black. This is true if the video that I'm attempting to play is from the UIImagePickerController selection or from the mainBundle. Once the UIImagePicker is selected, the video will not play.
I have gone through several steps of debugging and this does not happen with the UIImagePickerControll is presented in a modal view on the iPhone only when it's in a UIPopoverController on the iPad.
any ideas? anyone else able to successfully play a video on the iPad selected from a UIImagePickerController?
Turns out the answer is "roll your own" using ALAsssetsLibrary. UIImagePickerContorller doesn't work with video on iPads, and creating your own custom picker isn't too hard. There's sample code from the WWDC 2010 as well as code from Mat Tuzzolo on GitHub https://github.com/elc/ELCImagePickerController
I had this problem, that the video would not play after being picked from UIImagePickerController, but I wasn't fully releasing the popover. When I released it properly, it worked fine.
Thanks to prudence @ UIImagePickerController choosing video prevents MPMoviePlayerViewController instance from working
精彩评论