UIImagePickerController - 从照片库中选择背景视频

问题描述 投票:2回答:1

如何在后台模式下继续从照片库中选择视频?

我的意思是当我按下来自useimagePickerController - PhotoLibrary按钮并且视频开始压缩 - 在此压缩过程中(已附加屏幕截图)如果我按home button(i.e. go to background)然后来到foreground然后我得到info[UIImagePickerControllerMediaURL]作为null,那么应用程序是否可以继续在背景中也压缩视频并在来到url时返回适当的foreground

截图:

enter image description here

我的didFinishPickingMediaWithInfo

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{


NSURL *url = info[UIImagePickerControllerMediaURL];

NSLog(@"url : %@",url);

[picker dismissViewControllerAnimated:YES completion:nil];

}

P.S:如果我们通过camera录制视频并转到背景,那么它将停止录制,我们可以在前景后使用它。

我想到了一个解决方法 - UIBackgroundTaskIdentifier但它不适用于所有情况,如果视频很大,那么它有时间限制,所以寻找任何其他解决方案!

任何帮助将不胜感激! :)

ios objective-c uiimagepickercontroller
1个回答
1
投票

如果我们想在video期间从UIImagePickerController photolibrary在背景中连续选择video is compressing and user press home button(app go in background),那么我们必须使用UIBackgroundTaskIdentifier继续执行背景或任何其他背景方式,以保持应用程序在后台工作(不太可能!)。现在,UIBackgroundTaskIdentifier有时间限制,所以我们不能选择任何大小的视频,所以如果我们限制视频持续时间,那么我们可以在背景中连续选择它,如,

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoMaximumDuration = 60.0;

 self.backgroundTask = UIBackgroundTaskInvalid;

            self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
                NSLog(@"Background handler called. Not running background tasks anymore.");
                [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
                self.backgroundTask = UIBackgroundTaskInvalid;
            }];

[self presentViewController:picker animated:YES completion:NULL]; 

使用UIImagePickerController,我们可以做很多事情只是为了在后台选择视频。如果有人想在背景中选择大型视频,那么他/她应该考虑ALAssetLibraryPhotos framework

© www.soinside.com 2019 - 2024. All rights reserved.