Observer to see when the video playback started
player = AVPlayer(url: URL(fileURLWithPath: path))
player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "rate" {
if player.rate > 0 {
print("video started")
}
}
}
Knowing when AVPlayer object is ready to play
How to detect AVPlayer actually started to play in swift
Selecting Subtitles and Alternative Audio Tracks
if IsMuted == false {
IsMuted = true
musicPlayer.volume = 0
} else {
IsMuted = false
musicPlayer.volume = 1
}
}