Im trying to find a way to observe the player so that I can detect when a user increases or decreases the volume on the Apple TV. I have managed to get this to work for iOS by using:
var audioSession: AVAudioSession?
audioSession?.addObserver(self, forKeyPath: "outputVolume", options: [.new], context: &videoPlayerViewControllerKVOContext)
if keyPath == "outputVolume" {
guard let mute = (change?[NSKeyValueChangeKey.newKey] as? NSNumber)?.floatValue else {
return
}
var isMuted = false
if (mute == 0) && (!player.isMuted) {
isMuted = true
} else if (mute.isZero) && (player.isMuted) {
isMuted = false
}
}
However this doesn't work for tvOS. Is there a way to do this on tvOS?