Corrado
Corrado

Reputation: 41

Picture in picture button disabled

I'm developing a live video player and I want to use the new Picture in Picture option. I based the player on an AVPlayerViewController and this is my code.

class PlayerViewController: AVPlayerViewController {
    var link = NSURL ()

    override func viewDidLoad() {
        super.viewDidLoad()
        setVideoPlayer()

        do {
            try AVAudioSession.sharedInstance().setActive(true)
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        }
        catch {
            print("Audio session setCategory failed")
        }

    }
}


typealias VideoPlayer = PlayerViewController
extension VideoPlayer {

        func setVideoPlayer() {
        player = AVPlayer(URL: (link))
        player!.play()

    }
}

I don't understand why PictureInPicture works well on iPad Air 2 simulator but in the real device the PiP button stays disabled although visible, and the user can't click on it.

Upvotes: 4

Views: 1887

Answers (1)

Amulya
Amulya

Reputation: 182

Make sure to set audio session in AppDelegate.swift func application(application:, didFinishLaunchingWithOptions launchOptions:) find below the sample code .

    let audioSssn = AVAudioSession.sharedInstance();

    do {

        try audioSssn.setCategory(AVAudioSessionCategoryPlayback)

    }

    catch {

        print("Audio session setCategory failed")

    }

Upvotes: 4

Related Questions