2

I am playing back a queue of multiple audio files using AVQueuePlayer. I have not been able to detect that the last audio file finished playback.

For AVAudioPlayer there is AVAudioPlayerDelegate with audioPlayerDidFinishPlaying, however that seems not to apply to AVQueuePlayer.

How do I detect that AVQueuePlayer finished playback?

Björn
  • 111
  • 10

1 Answers1

4

Figured it out. Need to add before inserting an item:

NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidFinishPlaying(sender:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem

which then calls

@objc func playerDidFinishPlaying(sender: Notification) {
    print("Finished playing")
}
Björn
  • 111
  • 10