【问题标题】:AVAssetWriter fails once App goes in background一旦 App 进入后台,AVAssetWriter 就会失败
【发布时间】:2013-04-27 13:15:07
【问题描述】:

我正在开发从图像创建视频的 iOS 应用程序。我正在使用AVAssetWriter 来实现这一点。一切正常。但是当应用程序进入后台并切换回来时,视频写入失败。当我切换回应用程序时,AVAssetWriterfinishWritingWithCompletionHandler 没有被调用。

可能与 AVAssetWriter fails when Application enters Background during Rendering 重复,但我没有从那里得到任何帮助。

对此有什么想法吗?

谢谢

【问题讨论】:

  • 您设置了后台处理任务吗?您的问题缺乏细节。

标签: iphone ios objective-c avassetwriter


【解决方案1】:

此答案基于您希望视频在后台继续渲染的假设。

我通过要求操作系统授予应用后台任务权限(在有限的时间内)在我的应用中解决了这个问题。这个答案也可能对你有帮助 iOS generating a video in the background task

    @property (nonatomic,assign) UIBackgroundTaskIdentifier __block backgroundRenderingID;

    UIApplication *app = [UIApplication sharedApplication];

    _backgroundRenderingID = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:_backgroundRenderingID];
        _backgroundRenderingID = UIBackgroundTaskInvalid;
    }];

完成后别忘了放手!

[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2016-01-09
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2016-04-09
    • 2016-08-03
    相关资源
    最近更新 更多