How to detect fullscreen mode using AVPlayerViewController in Swift?
Updated for Swift 3:
Add an observer for the playerViewController
object:
playerViewController(self, forKeyPath: "videoBounds", options: NSKeyValueObservingOptions.new, context: nil)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
{
if keyPath == "videoBounds"
{
if let rect = change?[.newKey] as? NSValue
{
if let newrect = rect.cgRectValue as CGRect?
{
// 200 is height of playerViewController in normal screen mode
if newrect.size.height <= 200
{
print("normal screen")
}
else
{
print("full screen")
}
}
}
}
}
Handle when AVPlayerViewController goes full screen
The answer is here suggesting to observe the videoBounds of the AVPlayerViewController that I initially observed but did not work for me.
This solution is not always working. The notification related to the videoBounds property of the AVPlayerViewController controller is not always issued.
Related Topics
What Is Difference Between Self.Timer = Nil VS [Self.Timer Invalidate] in iOS
How to Make a Conical Gradient in iOS Using Core Graphics/Quartz 2D
Parsing JSON Using the New Swift 3 and Alamofire
Admob 7.3.1 and Swift 2.0 - Module Not Found
Autolayout Ignores Multi-Line Detailtextlabel When Calculating Uitableviewcell Height (All Styles)
Stop Skaction That Repeatsforever - Sprite Kit
Uiwebview Stringbyevaluatingjavascriptfromstring Hangs on iOS5.0/5.1 When Called Using Gcd
Animating Calayer's Shadowpath Property
How to Get an Error Description When Playback Fails on Mpmovieplayercontroller
How Could You Make a Uilabel Wrap Around an Image (Like Shown)
iOS Multiple Right and Left Align on Same Line
Uilongpressgesturerecognizer on Uitableviewcell - Double Call
Xcode 4.2 Mainstoryboard Not Found
Grouping Coredata by Date() in Swiftui List as Sections
How to Detect Whether an iOS Device Is in Silent Mode or Not
Swift - Add Gesture Recognizer to Object in Table Cell
Error Using Swift - Instance Member Cannot Be Used on Type 'Viewcontroller'