我正在开发一个需要合并多个视频的应用程序。我正在使用AVExportSession导出合并的视频。我还显示了导出视频的进度条。它运行正常。
当我们锁定屏幕或将应用程序置于后台模式时,就会发生此问题。这次如果正在导出,则在将应用程序置于后台模式后立即失败。
我也尝试过使用后台任务。检查以下代码。
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
UIApplication *application = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier background_task; /
background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//START EXPORT SESSION
[exporter exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exporter];
});
}];
NSLog(@"Running in the background!");
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});
}
}
但这似乎不起作用。我究竟做错了什么?任何帮助,将不胜感激。
我知道有可能在后台运行AVExportSession,因为我在应用商店中发现许多可以做到这一点的应用。
提前致谢。
最佳答案
将此代码替换为[self exportDidFinish:exporter];
[self performSelectorOnMainThread:@selector(exportDidFinish:) withObject:exporter waitUntilDone:YES];
关于ios - AVExportSession将在后台继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16793221/