【问题标题】:AVAssetDownloadDelegate methods for HLS getting called before I pause AVplayer在我暂停 AVplayer 之前调用 HLS 的 AVAssetDownloadDelegate 方法
【发布时间】:2016-11-16 12:08:12
【问题描述】:

我有这段代码应该下载音频流并按下暂停下载应该停止

func setupAssetDownload() {

    let configuration = URLSessionConfiguration.background(withIdentifier: "downloadIdentifier")
    let downloadSession=AVAssetDownloadURLSession(configuration: configuration, assetDownloadDelegate: self, delegateQueue: OperationQueue.main)
    let url = NSURL(string: "http: ... stream url")
    let asset = AVURLAsset(url: url as! URL)

    if #available(iOS 10.0, *) {
        let downloadTask = downloadSession.makeAssetDownloadTask(asset: asset,assetTitle: "downloadedAudio",assetArtworkData: nil,options: nil)
        downloadTask?.resume()
        let playerItem = AVPlayerItem(asset: (downloadTask?.urlAsset)!)
        player = AVPlayer(playerItem: playerItem)
        player.play()
    } else {
        // Fallback on earlier versions
    }

}
func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
    UserDefaults.standard.set(location.relativePath, forKey: "assetPath")
    print("Done")
}

但是当我启动应用程序时,它已经显示“完成”。 我正在使用广播流 URL。

【问题讨论】:

    标签: swift avaudioplayer audio-streaming


    【解决方案1】:

    AVAssetDownloadURLSession 用于下载资产。如果你只是想玩它,你 AVPlayer 可以处理。

    或者,如果您想取消下载,您可以致电downloadTask.cancel()

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多