An NSViewController
subclass that can present its child view controller in picture-in-picture mode.
Please note that this project links against PIP.framework
, which is private. Don't try to submit apps using this to the App Store.
Add the following line to your Cartfile
and follow the integration instructions for Carthage:
github "insidegui/PIPContainer" ~> 1.0
Add the following line to your Podfile
and then run pod install
:
pod 'PIPContainer'
Drag PIPContainer.xcodeproj
to your project and add PIPContainer.framework
to the Embedded Binaries
section.
The way it works is you add the view controller you want to display in the PiP as a child view controller of PIPContainerViewController
. This can all be done using storyboards (see demos).
After you have the correct containment setup, simply call togglePIP
on PIPContainerViewController
to enter/exit PiP mode.
private var pip: PIPContainerViewController? {
return parent as? PIPContainerViewController
}
func togglePictureInPictureMode() {
pip?.togglePIP(nil)
}
You can also link UI controls like buttons and menus directly to the togglePIP
action in Interface Builder by control-dragging to the First Responder and selecting the action togglePIP:
.
PIPContainerViewController
has many block properties that you can use to get notifications about state changes.
pipDidPause
: Called when the pause button is pressed in the PiP panelpipDidPlay
: Called when the play button is pressed in the PiP panelpipWillOpen
: Called when the PiP panel is about to be opened. This is the best moment to set theisPlaying
property ofPIPContainerViewController
to reflect the state of your playerpipWillClose
: Called when the PiP panel is about to be closedpipDidClose
: Called after the PiP panel is closed and the view controller is back to its original position
I encourage you to have a look at the demos to get a better understanding of how PIPContainer works: