What is the east way to track when song finished playing with AVPlayer in Swift?
Is there any function which is called when avplayer finished playing, or I should combin
For Swif3 you will need to change as follow:
func play(url: NSURL) {
let item = AVPlayerItem(URL: url)
NotificationCenter.default.addObserver(self,selector:Selector("playerDidFinishPlaying"), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: item)
let player = AVPlayer(playerItem: item)
player.play()
}
func playerDidFinishPlaying() {
// Your code here
}