繁体   English   中英

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

[英]UIImagePickerController - picking video in background from photo library

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

我的意思是当我按下imagePickerController - PhotoLibrary use按钮时imagePickerController - PhotoLibrary和视频开始压缩 - 在这个压缩过程中(附有截图)如果我按下home button(ie go to background)然后来到foreground然后我得到info[UIImagePickerControllerMediaURL]null ,那么应用程序是否有可能在后台继续压缩视频并在进入foreground时返回正确的url

截屏 :

在此处输入图片说明

didFinishPickingMediaWithInfo

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


NSURL *url = info[UIImagePickerControllerMediaURL];

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

[picker dismissViewControllerAnimated:YES completion:nil];

}

PS:如果我们通过camera录制视频并转到后台,则它会在那里停止录制,我们可以在进入前台后使用它。

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

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

如果我们想在video is compressing and user press home button(app go in background)期间通过UIImagePickerControllerphotolibrary在后台连续选择video 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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