【问题标题】:What is the best way to update downloaded HLS files in iOS app?在 iOS 应用程序中更新下载的 HLS 文件的最佳方法是什么?
【发布时间】:2021-03-17 21:54:23
【问题描述】:

我正在开发一个 iOS 应用程序。我实现了下载 HLS 视频文件的逻辑。我使用AVAssetDownloadURLSessionAVAggregateAssetDownloadTaskURLSessionConfiguration.background

如果在服务器上更新了 HLS 文件,我需要实现更新 HLS 文件的逻辑。 NSURLRequest.CachePolicy 可以做到这一点吗?还是有其他方法可以做到这一点? 任何帮助表示赞赏。

会话配置:

private let assetSessionConfiguration: URLSessionConfiguration = {
    let configurationIdentifier = Bundle.main.bundleIdentifier ?? "identifier"
    let configuration = URLSessionConfiguration.background(withIdentifier: configurationIdentifier)
    configuration.networkServiceType = .video
    configuration.requestCachePolicy = .useProtocolCachePolicy
    if #available(iOS 13.0, *) {
        configuration.allowsExpensiveNetworkAccess = true
    }

    if #available(iOS 13.0, *) {
        let memoryMBAmount = 10
        let diskMBAmount = 2048
        configuration.urlCache = URLCache(memoryCapacity: memoryMBAmount * 1024 * 1024, diskCapacity: diskMBAmount * 1024 * 1024, directory: CustomURL)
    } else {
        configuration.urlCache = URLCache.shared
    }

    return configuration
}()

【问题讨论】:

    标签: avfoundation http-live-streaming avassetdownloadurlsession


    【解决方案1】:

    一种方法是在您的主播放列表响应中设置cache-control HTTP 标头。

    【讨论】:

    • 我们可以将它与 AVAggregateAssetDownloadTask 一起使用,还是我们需要发出额外的请求?你能举个例子吗?谢谢!
    • 是的,您可以将它与 AVAggregateAssetDownloadTask 一起使用!
    • 嘿!你能看看会话配置吗?我试过了,但它对我不起作用。我应该改变什么?
    • cache-control 是您必须设置的 HTTP 标头。 requestCachePolicy 应该没有轴承。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    相关资源
    最近更新 更多