Björn
Björn

Reputation: 121

How can I detect that AVQueuePlayer finished playing?

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?

Upvotes: 2

Views: 736

Answers (1)

Björn
Björn

Reputation: 121

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")
}

Upvotes: 5

Related Questions