使用AVAssetWriter导出视频时,退到后台,进入时,失败,status = AVAssetExportSessionStatusFailed
注意
:退到后台等几秒钟,进入会失败
You use an AVAssetWriter
object to write media data to a new file of a specified audiovisual container type, such as a QuickTime movie file or an MPEG-4 file, with support for automatic interleaving of media data for multiple concurrent tracks.
You can only use a given instance of AVAssetWriter
once to write to a single file. If you want to write to files multiple times, you must use a new instance of AVAssetWriter
each time.
解决方案
1.进入前台判断导入视频的文件是否成功(如是否存在),尝试重新导出
2.使用后台线程,
- (void)applicationDidEnterBackground:(NSNotification *)note
{
UIApplication *app = [UIApplication sharedApplication];
_backgroundRenderingID = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:_backgroundRenderingID];
_backgroundRenderingID = UIBackgroundTaskInvalid;
}];
NSTimeInterval time1 = app.backgroundTimeRemaining; //180s
}
//执行完任务,记得告诉应用,防止被os杀掉,You can find out how much time is available using the [backgroundTimeRemaining]property.
[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];
注意:
如果执行任务超过10分钟,最好就是暂停任务。(我测试返回后台保持时间是180s)
参考