Skip to content

Instantly share code, notes, and snippets.

@bleft
Created November 8, 2016 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleft/0b9716e35a0b936382a55e15c300c757 to your computer and use it in GitHub Desktop.
Save bleft/0b9716e35a0b936382a55e15c300c757 to your computer and use it in GitHub Desktop.
recognizes when a AVPlayerController changes to full screen or back. There you can handle auto rotation behavior or other smart things
// add your view as observer
func addVideoBoundsObserver(){
playerController?.contentOverlayView?.addObserver(self, forKeyPath: "bounds", options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "bounds" {
guard let new = change?[NSKeyValueChangeKey.newKey] as? CGRect
else { return }
if new.size == UIScreen.main.bounds.size {
print("Player in full screen")
} else {
print("Player not in full screen")
}
}
}
// dont forgett to remove the observer!
deinit {
playerController?.contentOverlayView?.removeObserver(self, forKeyPath: "bounds")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment