Picture-in-Picture Mode Implementation for iOS App

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Picture-in-Picture Mode Implementation for iOS App
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1054
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Picture-in-Picture Mode for iOS Apps

PiP on iOS doesn't work automatically: app must explicitly support via AVKit API, properly configure AVAudioSession, and handle PiP window lifecycle. Seems simple—until you deal with custom content, not AVPlayer.

Basic Implementation with AVPlayerViewController

Simplest path—AVPlayerViewController. PiP out of the box: set allowsPictureInPicturePlayback = true, configure AVAudioSession, PiP button appears automatically.

import AVKit

class VideoViewController: UIViewController {
    private var player: AVPlayer!
    private var playerViewController: AVPlayerViewController!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Mandatory: playback category for background playback
        try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)
        try? AVAudioSession.sharedInstance().setActive(true)

        player = AVPlayer(url: videoURL)
        playerViewController = AVPlayerViewController()
        playerViewController.player = player
        playerViewController.allowsPictureInPicturePlayback = true

        addChild(playerViewController)
        view.addSubview(playerViewController.view)
        playerViewController.view.frame = view.bounds
        playerViewController.didMove(toParent: self)
    }
}

Add to Info.plist: UIBackgroundModesaudio. Without it, PiP shows video but sound disappears on background transition.

Custom PiP: AVPictureInPictureController

Custom video player (not AVPlayerViewController)—need AVPictureInPictureController directly. Initialized via AVPictureInPictureController(playerLayer:) for AVPlayerLayer or AVPictureInPictureControllerContentSource with AVPictureInPictureSampleBufferPlaybackDelegate for custom rendering.

class CustomVideoPlayer: UIView {
    private var playerLayer: AVPlayerLayer!
    private var pipController: AVPictureInPictureController?

    func setupPiP() {
        guard AVPictureInPictureController.isPictureInPictureSupported() else { return }

        pipController = AVPictureInPictureController(playerLayer: playerLayer)
        pipController?.delegate = self
        pipController?.canStartPictureInPictureAutomaticallyFromInline = true // auto-start on background
    }
}

extension CustomVideoPlayer: AVPictureInPictureControllerDelegate {
    func pictureInPictureControllerWillStartPictureInPicture(_ controller: AVPictureInPictureController) {
        // hide custom controls over video
    }

    func pictureInPicture(_ controller: AVPictureInPictureController,
                          restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) {
        // restore UI when closing PiP
        completionHandler(true)
    }
}

PiP with Arbitrary Content (iOS 15+)

AVPictureInPictureVideoCallViewController (iOS 15+)—non-video content: live camera, WebRTC, animations. Content renders in UIView, placed in PiP container via AVPictureInPictureControllerContentSource(activeVideoCallSourceView:contentViewController:).

Messengers use this (FaceTime, Zoom) for video calls over other apps. Key restriction: content must be truly "active call"—Apple may reject if abused in review.

Common Problems

PiP doesn't start on background. 90% of cases: missing canStartPictureInPictureAutomaticallyFromInline = true, or UIBackgroundModes: audio not in Info.plist, or AVAudioSession inactive.

Video freezes after PiP exit. In restoreUserInterfaceForPictureInPictureStopWithCompletionHandler, return completionHandler(true) only after UI fully restored. Calling immediately—system thinks restoration complete and does transition animation, but your UI not ready.

Custom buttons in PiP window. iOS 16+—AVPictureInPictureController.requiresLinearPlayback = false and custom playbackControlsIncludeTransportBar, playbackControlsIncludeInfoViews. Before iOS 16—standard controls only.

Timelines

2–3 working days for basic PiP with AVPlayerViewController. Custom player with AVPictureInPictureController and non-standard content—up to 5 days. Cost calculated individually.