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 =
Since AVPlayer is very limited (for example you cannot change url there without regenerate whole AVPlayer I think you should use AVQueuePlayer:
From the docs:
AVQueuePlayer is a subclass of AVPlayer used to play a number of items in sequence. Using this class you can create and manage a queue of player items comprised of local or progressively downloaded file-based media, such as QuickTime movies or MP3 audio files, as well as media served using HTTP Live Streaming.
So in Swift 3 it will work like this:
lazy var playerQueue : AVQueuePlayer = {
return AVQueuePlayer()
}()
...
func playTrackOrPlaylist{
if let url = track.streamURL() { //this is an URL fetch from somewhere. In this if you make sure that URL is valid
let playerItem = AVPlayerItem.init(url: url)
self.playerQueue.insert(playerItem, after: nil)
self.playerQueue.play()
}
}