ios - 下载 HLS 内容未启动
问题描述
我按照 Apple 的媒体播放编程指南下载 HLS 内容。以下实现通常可以正常工作,但偶尔会在没有明显原因的情况下停止工作。委托方法不会报告任何内容,既不会报告下载进度,也不会报告错误。下载只是拒绝启动。发生这种情况时,要重新开始下载,唯一的方法是重新启动设备。有没有人面临同样的问题?有人可以指点我如何解决这个问题吗?
func setupAssetDownload() {
// Create new background session configuration.
let configuration = URLSessionConfiguration.background(withIdentifier: "Player")
configuration.isDiscretionary = true
configuration.timeoutIntervalForResource = 300
// Create a new AVAssetDownloadURLSession with background configuration, delegate, and queue
downloadSession = AVAssetDownloadURLSession(configuration: configuration,
assetDownloadDelegate: self,
delegateQueue: OperationQueue.main)
}
创建和配置下载会话:
func assetDownload(for item: DownloadItem) {
let asset = AVURLAsset(url: item.url)
asset.resourceLoader.preloadsEligibleContentKeys = true
asset.resourceLoader.setDelegate(self, queue: DispatchQueue.global(qos: .default))
// Create new AVAssetDownloadTask for the desired asset
guard let task = downloadSession.makeAssetDownloadTask(asset: asset,
assetTitle: item.title!,
assetArtworkData: data,
options: [AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: 2_787_000])
else {
status[item.url!] = .error
return
}
task.taskDescription = item.title!
// Start task and begin download
task.resume()
}
解决方案
推荐阅读
- c - 从字符串初始化 uInt128 值
- bash - 如何按字符串集中两个不同分隔符之间包含的数值进行bash排序
- python - 错误 take() 不接受布尔索引器
- r - 如何使用 gsub 保留部分字符并删除 R 中的其他任何内容?
- ios - React-Native/XCode/iOS 模拟器 - os/kern 没有可用空间错误
- mysql - 如何在每个 Sequelize 连接上执行命令?
- oauth-2.0 - 如何在 Outlook(桌面或应用程序)中为自己的 Postfix/Dovecot 邮件服务器启用 Oauth2 登录
- reactjs - AWS Amplify 中缺少 API 和存储函数
- python - Android Studio 无法使用 chaquopy python 打开 COM 端口
- python - 是否有其他选项来检查表是否在 SQl 连接中,我正在尝试使用 dialect.has_table