当我尝试将AVURLAsset.init
用于具有类似以下网址的音频时,网址下方是示例网址。
https://web-web.test.net/media/abcdefghijklmnopqrst?sr=abcdefghijklmnopqrst
呼叫
audioAsset.statusOfValue()
返回为.failed
。请让我知道是否有任何建议。以下是我编写的完整代码。
if let url = URL(string: urlString) {
audioAsset = AVURLAsset.init(url: url)
if let audioAsset = audioAsset {
let keys = ["playable"]
audioAsset.loadValuesAsynchronously(forKeys: keys, completionHandler: {
let playableStatus = audioAsset.statusOfValue(forKey: keys[0], error: nil)
switch playableStatus {
case .unknown, .loading, .failed, .cancelled:
return
case .loaded:
DispatchQueue.main.async {
let playerItem = AVPlayerItem.init(asset: audioAsset)
self.audioPlayer.insert(playerItem, after: nil)
self.audioPlayer.play()
})
}
break
}
})
}
}