我的应用工作正常iPhone
但现在我移植到iPad
,要从库中选择视频,我们必须使用UIPopoverController
(这是nonatomic
的属性属性)同时解除popover
中的imagePickerController
:
- (UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
委托方法会自动调用我的didFinishMovie
并终止它。
-(void)showPopOverGalleryusingDelegate:(id )delegate {
if ([self.popover isPopoverVisible]) {
[self.popover dismissPopoverAnimated:YES];
} else {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] )
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = delegate;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
imagePicker.allowsEditing = NO;
self.popover = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
CGRect popoverRect = [self.view convertRect:[_galleryButton frame]
fromView:[_galleryButton superview]];
[self.popover presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// 1 - Get media type
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
// 2 - Dismiss image picker
[self dismissViewControllerAnimated:NO completion:nil];
if (_popover != nil) {
[_popover dismissPopoverAnimated:YES];
_popover=nil;
}
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
// 3 - Play the video
NSLog(@"imageDelegate");
_vURL =[info objectForKey:UIImagePickerControllerMediaURL];
_theMovie = [[MPMoviePlayerViewController alloc]
initWithContentURL:_vURL];
_theMovie.moviePlayer.controlStyle = MPMovieControlStyleNone;
_theMovie.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:_theMovie animated:YES completion:nil];
[_theMovie.moviePlayer prepareToPlay];
// 4 - Register for the playback finished notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification object:_theMovie.moviePlayer];
[_theMovie.moviePlayer play];
[self customPlaybackControls];
}
}
根据我的经验,这是非常不寻常的,我不能自己解决这个问题,我需要对此有新的看法,非常感谢。