PIP button in iPhone Avplayer

Viewed 1394

I enabled Audio,AirPlay and Picture in Picture background modes in project's Capabilities.

My problem is this:

If I run app on iPad device I see the PiP button and I can enabled PiP mode. If I run app on iPhone device I don't see PiP button, but I don't understand why.

enter image description here

2 Answers

Open Xcode -> Go to Your project -> select "Signing and Capabilities" -> add new capability with "+" button. -> Add "Background Modes" Capability and check "Audio,AirPlay and Picture in Picture" (image below)enabling PiP Capabilty After that open your AppDelegate and add audio session support for PiP as in code below:

    func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    let audioSession = AVAudioSession.sharedInstance()
    do {
        try audioSession.setCategory(.playback)
        try audioSession.setActive(true, options: [])
    } catch {
        print("Setting category to AVAudioSessionCategoryPlayback failed.")
    }
    
    return true
}

After implementing all steps above, your PiP button should be present in your player.

You propably do not have iOS 14+ on iPhone. For iPad iOS 13 is sufficient for PiP , but for iPhones it is only iOS 14 and higher.

Related