简体   繁体   中英

UIImagePickerController - picking video in background from photo library

How to continue picking video from photo library in background mode ?

I mean when I press use button from imagePickerController - PhotoLibrary and video is started to get compressing - During this compression process (have attached screenshot) if I press home button(ie go to background) and then come to foreground then I got info[UIImagePickerControllerMediaURL] as null , so is it possible that app can continue compressing video in background also and return proper url when come to foreground ?

Screenshot :

在此处输入图片说明

My didFinishPickingMediaWithInfo ,

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


NSURL *url = info[UIImagePickerControllerMediaURL];

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

[picker dismissViewControllerAnimated:YES completion:nil];

}

PS : If we record video by camera and go to background then it will stop recording there and we can use it after coming foreground.

I have thought of one workaround - UIBackgroundTaskIdentifier but it will not work in every case, if video is big then it have time limit, so looking for any other solution!

Any help will be appreciated! :)

IF we want to pick video continuously in background by UIImagePickerController from photolibrary during video is compressing and user press home button(app go in background) then we have to use UIBackgroundTaskIdentifier for continue execution in background or any other background way which keeps app working in background(less possible thing!). Now, UIBackgroundTaskIdentifier has time limit so we can't pick any size of video, so if we restricted video time duration then we can pick it continuously in background something like,

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

With UIImagePickerController we can do that much only to pick video in background. If anyone want to pick large video in background then he/she should take look into ALAssetLibrary or Photos framework .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM