UIImagePickerControllerSourceTypePhotoLibrary"解码器忙"选择视频时出错

时间:2017-03-17 12:11:01

标签: ios video avfoundation uiimagepickercontroller

我遇到的问题是,从库中挑选了几个视频(一个接一个)后,视频播放器(UIImagePickerController)的预览栏为黑色(但可以播放)。enter image description here

选择文件imagePickerController:didFinishPickingMediaWithInfo:在没有UIImagePickerControllerMediaURL的情况下调用。发生这种情况后,每次下次UIImagePickerController都会打开时发生。为了能够再次选择一部新电影,有时重启应用就足够了。有时手机甚至必须重新启动(或者我只是不耐烦)。

我发现了这个问题:AVPlayerItem fails with AVStatusFailed and error code "Cannot Decode"。我相信它有相同的背景,但我不知道在这种情况下如何解决问题。在应用程序内部,视频播放效果非常好。

用于呈现和解除UIImagePickerController的代码如下:

- (IBAction)openVideoLibrary:(id)sender {
    if (_allowVideoSelection) {

        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == NO || ![[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary] containsObject:(NSString*)kUTTypeMovie]) {
            return;
        }

        UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
        [pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        pickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString*)kUTTypeMovie, nil];
        [pickerController setEditing:NO];
        [pickerController setDelegate:self];
        [self presentViewController:pickerController animated:YES completion:nil];
    }
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSLog(@"info: %@", info);

    if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
        [picker dismissViewControllerAnimated:YES completion:^{
            if (![info valueForKey:UIImagePickerControllerMediaURL]) {
                NSLog(@"Error: No media URL");
                return;
            }
            else {
                NSLog(@"Yey media");
            }
        }];
    }
}

有什么想法可以更好/更清晰地相互挑选多个媒体文件?拣选选项在几个阶段集成在工作流程中,因此无法一起挑选图像。

1 个答案:

答案 0 :(得分:0)

只有一定数量的AVPlayers可以并行运行。如果取消包含AVPlayer属性的UIViewController,则AVPlayer不会自动解除分配并保持活动状态,直到iOS在后台杀死它。如果重复分配AVPlayer而不设置AVPlayerLayer.player = nil,则iOS不允许实例化另一个AVPlayer。错误:" AVPlayerItem失败,AVStatusFailed和错误代码"无法解码"棱。