Eliasz Sawicki

Eliasz Sawicki

iOS developer from Gdansk

Queueing audio files with AVQueuePlayer

- 1 min

Today’s short post will cover queueing audio files using Swift. In order to do this we will be using AVQueuePlayer.

Import AVFoundation in order to use the AVQueuePlayer

Create an instance of 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.

Add audio file to queue.

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.

Play/pause/skip.

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 company blog

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora