Stephen Hsu
Stephen Hsu

Reputation: 5177

How to let AVPlayer play multiple items?

I'm trying to play multiple mp3's with AVPlayer. I fetch URLs of the mp3's and then let AVPlayerplays them one by one.

My first attempt is letting a single AVPlayerplays all the mp3's with replaceCurrentItemWithPlayerItem method. But there is no sound except for the first song.

When I try to generate AVPlayer for every single item, and let each AVPlayer plays its item, the app works as I wished.

My question is, is AVPlayer designed to play a single item? If I don't want to allocate a new AVPlayer for each item, I have to use AVQueuePlayer to play multiple items, right? Which method is preferred?

Upvotes: 4

Views: 2187

Answers (1)

Stephen Hsu
Stephen Hsu

Reputation: 5177

AVQueuePlayer works perfectly for this case. It'll remove played items automatically.

Upvotes: 3

Related Questions