When i try using AVURLAsset.init
to an audio having url something similar below . Below url is example url.
https://web-web.test.net/media/abcdefghijklmnopqrst?sr=abcdefghijklmnopqrst
Calling
audioAsset.statusOfValue()
returns as .failed
. Please let me know if any sugesions. Below is complete code i have written.
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
}
})
}
}