gpt4 book ai didi

ios - NSURLErrorDomain error -1 尝试下载 http Live Streaming Video 时

转载 作者:行者123 更新时间:2023-11-29 00:25:09 26 4
gpt4 key购买 nike

我一直在尝试使用 AVAssetDownloadDelegate 从 url 下载视频。我可以播放响应中的视频,但无法使用以下代码下载媒体。

我收到此错误“操作无法完成。(NSURLErrorDomain 错误 -1。)”

这是我使用的代码

@IBOutlet weak var view1: UIView!

var configuration : URLSessionConfiguration? = nil

var downloadSession : AVAssetDownloadURLSession? = nil

override func viewDidLoad() {
super.viewDidLoad()


configuration = URLSessionConfiguration.background(withIdentifier: "downloadIdentifier")


downloadSession = AVAssetDownloadURLSession(configuration: configuration!,
assetDownloadDelegate: self,
delegateQueue: nil)

let url = URL(string: "http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8")
let asset = AVURLAsset(url: url!)

let downloadTask = downloadSession?.makeAssetDownloadTask(asset: asset,
assetTitle: "assetTitle",
assetArtworkData: nil,
options: nil)

// Start task and begin download
downloadTask?.resume()


let playerItem = AVPlayerItem(asset: (downloadTask?.urlAsset)!)
let player = AVPlayer(playerItem: playerItem)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = view1.bounds
view1.layer.addSublayer(playerLayer)
player.play()


}

这是我实现的代表

func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
print("Downloaded to Location : \(location)")
}



func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange) {
var percentComplete = 0.0
// Iterate through the loaded time ranges
for value in loadedTimeRanges {
// Unwrap the CMTimeRange from the NSValue
let loadedTimeRange = value.timeRangeValue
// Calculate the percentage of the total expected asset duration
percentComplete += loadedTimeRange.duration.seconds / timeRangeExpectedToLoad.duration.seconds
}
print(percentComplete *= 100)
// Update UI state: post notification, update KVO state, invoke callback, etc.
}

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {


if (error != nil){

print(error?.localizedDescription)



}else{

print("Error")

}

}

请看这个..

最佳答案

这个 HLS 下载 API 在很多方面都被破坏了。您可以尝试的几件事:

  1. 在 makeAssetDownloadTask 调用中指定比特率(选项参数)
  2. 修改他们的示例应用程序以下载您的视频,这可以帮助您进行调试,看看您的播放列表是否有任何问题。
  3. 实现 func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didResolve returned MediaSelection: AVMediaSelection) 委托(delegate),看看它是否被调用。

关于ios - NSURLErrorDomain error -1 尝试下载 http Live Streaming Video 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43227254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com