I am getting mp3 url as a response of api calling. I want to play that audio, so how can i do that? (ios swift)
here is my response
{
content =
var player : AVPlayer?
func playSound()
{
guard let url = URL(string: "https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3")
else
{
print("error to get the mp3 file")
return
}
do{
try AVAudioSession.sharedInstance().setCategory(.playback, mode.default)
try AVAudioSession.sharedInstance().setActive(true)
player = try AVPlayer(url: url as URL)
guard let player = player
else
{
return
}
player.play()
} catch let error {
print(error.localizedDescription)
}
}