I am trying to play the audio from remote URL.
let audioData = try! Data.init(contentsOf: URL)
do
{
self.audioPlayer = try AVAudioPlayer.init(data: data) //Throwing error sometimes
self.audioPlayer?.delegate = self
self.audioPlayer?.prepareToPlay()
self.audioPlayer?.play()
}
catch {
showErrorMessage("An error occurred while trying to extract audio file")
}
I have a list of audio url on my server. for some audio I am able to get the Data
but in the AVAudioPlayer's init method it is throwing the error. I am not able to get the actual cause for this.
I have the option of AVPlayer
but why this thing is causing the issue?