uiimagepickercontroller didfinishpickingmediawithinfo从库中selectvideo时未调用
我正在编写一个应用程序,用户可以从库中select照片和video。 我想在selectvideo时实现自己的video播放器,但应用程序立即启动具有selectbutton的默认video播放器。
didfinishpickingmediawithinfo函数不会被调用。 这仅在selectvideo时发生。 我可以显示选定的照片,因为在照片select的情况下调用委托方法。
为什么仅在从库中selectvideo时才会调用选取器的委托方法?
代码库button点击:
//Library access function displays photos and videos stored on the device - (IBAction)selectPhoto:(UIButton *)sender { UIImagePickerController *picker2 = [[UIImagePickerController alloc] init]; picker2.delegate = self; picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker2.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:picker2.sourceType]; picker2.allowsEditing = NO; self.picker2 = picker2; [self.picker dismissViewControllerAnimated:YES completion:^{ [self presentViewController:self.picker2 animated:YES completion:NULL];}]; }
我确实包括在视图控制器中的代表。 我研究过的许多问题都指出了在视图控制器的标题中缺less包含,但我向你保证他们在那里。
这里是包含的代码:
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>
我已经将NSLog语句放在委托方法中,并且在使用选取器时,我发现它们在所有其他情况下都被执行。 但是,在videoselect的情况下,NSLog语句不会出现。
如果有人有这个问题,并提出解决scheme,请分享。 我已经search了很多天,并没有find解决这个问题。
在这个线程中的人有同样的问题,但问题从未解决。
这个问题所提供的一切都是作为解决scheme提供的,我已经在我的程序中实现了
我已经按照要求添加了以下代码。
委托方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"didfinishpicking method triggered"); // Get the type of media selected NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; // Handling Media Capturing (Images/Videos) // When an image is taken if ([mediaType isEqualToString:(NSString *)kUTTypeImage] && picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Save the taken photo to the camera roll library UIImage *imageTaken = [info valueForKey:UIImagePickerControllerOriginalImage]; UIImageWriteToSavedPhotosAlbum(imageTaken, nil, nil, nil); // Update the library button image [self.imageButton setImage:imageTaken forState:UIControlStateNormal]; } // When a video is taken else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie] && picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Grab the URL for the video just taken NSURL *newVideo = [info objectForKey:UIImagePickerControllerMediaURL]; // Save the video to the camera roll UISaveVideoAtPathToSavedPhotosAlbum([newVideo path], nil, nil, nil); } // Handling Library Previewing // When an image is selected else if ([mediaType isEqualToString:(NSString *)kUTTypeImage] && picker.sourceType != UIImagePickerControllerSourceTypeCamera) { NSLog(@"A picture was selected from the library."); UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; self.libraryImage.image = image; self.libraryView.translatesAutoresizingMaskIntoConstraints = YES; [[UIApplication sharedApplication].keyWindow addSubview: self.libraryView]; } // When a video is selected else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie] && picker.sourceType != UIImagePickerControllerSourceTypeCamera) { NSLog(@"A video was selected from the library."); } }
即使时间延迟,build议picker2仍然被打破。 我用下面的答案来延迟电话。
这是我第一次尝试select一个video,然后select一张照片给出的输出。 在提交第二个select器之前,这是延迟的,然后延迟了。
> 2014-12-30 00:11:57.763 Sneak[228:907] [MPAVController] Autoplay: > Enabling autoplay 2014-12-30 00:11:57.766 Sneak[228:907] > [MPAVController] Autoplay: Skipping autoplay, disabled (for current > item: 0, on player: 1) 2014-12-30 00:11:57.853 Sneak[228:907] > [MPAVController] Autoplay: Enabling autoplay 2014-12-30 00:11:58.052 > Sneak[228:907] [MPCloudAssetDownloadController] Prioritization > requested for media item ID: 0 2014-12-30 00:11:58.897 Sneak[228:907] > [MPAVController] Autoplay: Skipping autoplay, disabled (for current > item: 0, on player: 1) 2014-12-30 00:11:58.911 Sneak[228:907] > [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1 2014-12-30 > 00:12:17.576 Sneak[228:907] didfinishpicking method triggered > 2014-12-30 00:12:17.579 Sneak[228:907] A picture was selected from the > library.
我做了更多的testing,发现在selectvideo时调用委托方法,但只有在默认的video播放器显示中点击selectbutton时才会调用委托方法。
我仍然不确定如何从库中selectvideo直接调用委托方法,并绕过默认的video播放器。 这额外的信息是否给任何其他的想法?
在呈现picker2之前设置属性picker2.allowsEditing=NO
让我知道,如果它适合你或不。
- 无法在applicationWillResignActive中获取当前ViewController
- 在Xamarin.iOS中创build一个Qt视图
- UIWebView不保存Cookie
- 在Swift中使用正则expression式进行简单search时,如何避免由于searchstring中的特殊字符造成的错误?
- 应该将translatesAutoresizingMaskIntoConstraints设置为true吗?
- HTTP POST请求,HTML表单input(login:用户/密码)浏览器模拟
- 用户的位置和电池的消耗
- 在4英寸的屏幕IOS应用程序中的黑色空间
- 如何在Phonegap / Cordova项目中实施Facebook移动安装广告跟踪?