AVExportSession在后台继续

时间:2013-05-28 13:22:40

标签: ios video avassetexportsession avmutablecomposition avasset

我正在处理一个需要合并多个视频的应用程序。我正在使用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,因为我在应用程序商店中找到了可以执行此操作的许多应用程序。

提前致谢。

1 个答案:

答案 0 :(得分:0)

替换[self exportDidFinish:exporter];

的此代码
[self performSelectorOnMainThread:@selector(exportDidFinish:) withObject:exporter waitUntilDone:YES];
相关问题