Queueing audio files with AVQueuePlayer
Today's short post will cover queueing audio files using Swift. In order to do this we will be using AVQueuePlayer.
Ps. Hold it as instance variable. If you create it as local variable, you will lose it after exiting the scope and audio won't play.
Here we will be adding a file which is added to our project. In order to do this, we create an instance of AVPlayerItem and add it to an existing queue. Passing nil as second argument of insertItem function will insert it at the end of the queue.
Tip: Once you call a play method, you can keep adding the files to queue and they will automatically start.
This article is cross-posted with my my personal blog.