0
私はAVAssetDownloadDelegateを使用してURLからビデオをダウンロードしようとしています。レスポンスからビデオを再生できますが、以下のコードを使用してメディアをダウンロードできません。NSURLErrorDomainエラー-1 httpライブストリーミングビデオをダウンロードしようとしたとき
私はこのエラー「が操作を完了できませんでした。(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")
}
}
これを見てください。..
こんにちは@noc、私は関数を実装し、デリゲートが呼び出されたことがないことがわかりました。私はビットレートも指定しましたが、私はまだ変化を観察することができませんでした。サンプルアプリケーションからコードを修正して、すぐに動作するかどうかを確認します。ありがとうございます –
ああ、私はあなたに尋ねて忘れました。シミュレータで実行していないことを確認してください。 HLSダウンロードはシミュレータでは動作しません。 – noc