Уведомления о прерываниях AVPlayer не работают - PullRequest
0 голосов
/ 20 сентября 2019

Я использую уведомление avplayer для обработки прерываний, но кажется, что уведомление не запускается

 private func setupNotifications() {
    let notificationCenter = NotificationCenter.default
    notificationCenter.addObserver(self, selector: #selector(handleInterruption), name: AVAudioSession.interruptionNotification, object: nil)
    notificationCenter.addObserver(self, selector: #selector(playerDidRecieveError(_:)), name: .AVPlayerItemNewErrorLogEntry, object: nil)
     notificationCenter.addObserver(self, selector: #selector(playerDidRecieveError(_:)), name: .AVPlayerItemFailedToPlayToEndTime , object: nil)
    notificationCenter.addObserver(self, selector: #selector(playerDidRecieveError(_:)), name: .AVPlayerItemPlaybackStalled , object: nil)  
}

1 Ответ

1 голос
/ 20 сентября 2019

Я использую что-то вроде:

NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemNewErrorLogEntry, object: player?.currentItem)

NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime, object: player?.currentItem)

NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemPlaybackStalled, object: player?.currentItem)

NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player?.currentItem)

@objc func playerDidFinishPlaying(note: NSNotification){
        print("Finished")
    }
...