gpt4 book ai didi

ios - 从库中选择视频时,uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:42 26 4
gpt4 key购买 nike

我正在编写一个应用程序,用户可以在其中从库中选择照片和视频。我想在选择视频时实现自己的视频播放器,但应用程序会立即启动具有选择按钮的默认视频播放器。

didfinishpickingmediawithinfo 函数不会被调用。这仅在选择视频时发生。我可以在屏幕上显示选定的照片,因为在选择照片的情况下会调用委托(delegate)方法。

为什么仅当从库中选择视频时不调用选择器的委托(delegate)方法?

库按钮点击代码:

//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];}];
}

我确实在 View Controller 中包含了委托(delegate)。我研究过的很多问题都指出 View Controller 的 header 中缺少包含,但我向您保证它们就在那里。

这是包含的代码:

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>

我在委托(delegate)方法中放置了 NSLog 语句,我发现在使用选择器时,它们在所有其他情况下都会执行。但是,在视频选择的情况下,NSLog 语句不会出现。

如果有人遇到过这个问题并提出解决方案,请分享。我已经搜索了很多天,没有找到解决这个问题的方法。

此人thread有同样的问题,但问题从未解决。

这一切 question必须提供解决方案,我已在我的程序中实现。

我已根据要求添加了以下代码。

委托(delegate)方法:

- (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.");
}
}

即使按照建议的时间延迟,picker2 仍然损坏。我使用了以下 answer延迟通话。

这是我第一次尝试选择视频然后选择照片时给出的输出。这是在呈现第二个选择器之前先关闭然后延迟运行的。

> 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.

我做了更多测试,发现在选择视频时会调用委托(delegate)方法,但只有在默认视频播放器显示上单击选择按钮时才会调用。

我仍然不确定如何在从库中选择视频时直接调用委托(delegate)方法并绕过默认视频播放器。这些额外信息是否会给其他人带来其他想法?

最佳答案

在呈现 picker2 之前设置属性 picker2.allowsEditing=NO

让我知道它是否适合你。

关于ios - 从库中选择视频时,uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27698188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com