Implementing Picture-In-Picture with AVKit and SwiftUI

Learn in this tutorial to implement Picture-in-Picture (PiP) with AVKit and SwiftUI using UIViewRepresentable & UIViewControllerRepresentable.

Implementing Picture-In-Picture with AVKit and SwiftUI

SwiftUI and AVKit let us display media from a player using VideoPlayer. We wrote about how to use it context of HTTP Live Streaming (HLS) if you are curious. It is really as simple as that.

Cool, right? But what if you want to keep watching a video while using other apps? Sadly, VideoPlayer does not support Picture in Picture (at least for now!). No need to panic! As usual, when we need specific features and behaviors that are still not supported in SwiftUI, we can use a little help from our friends UIViewRepresentable and UIViewControllerRepresentable.

So, let’s see how to create and manage an AVVideoPlayerController object which supports Picture in Picture (PiP).

Become a free member or log in to proceed.