Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Collapse the parent view of YTPlayerView when picture in Picture is enabled #516

Open
syedabdulsamad opened this issue Jul 18, 2024 · 0 comments

Comments

@syedabdulsamad
Copy link

Hi,

I want to navigate to different screens within my app when the video is in Picture in Picture (PIP) mode.
Here is my Code below

import UIKit
import YouTubeiOSPlayerHelper

class RQTarjmatulClassViewController: UIViewController {
    
    @IBOutlet var playerView: YTPlayerView!
    private var videoLink: String = ""
    private var startSecond : Int = 0
    
    
    internal static func instantiate(with videoLink: String, startSecond: Int) -> UIViewController? {
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "RQTarjmatulClassViewController") as? RQTarjmatulClassViewController
        vc?.videoLink = videoLink
        vc?.startSecond = startSecond
        return vc
    }


override func viewDidLoad() {
        super.viewDidLoad()
        playerView.delegate = self
        playerView.load(withVideoId: videoLink,  playerVars: ["playsinline": 1])
        
        let rightBarButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissSettings))
        rightBarButton.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.fontfor(.englishNormal, weight: .semiBold, style: .title3)], for: .normal)
        
        navigationItem.rightBarButtonItem = rightBarButton
}

@objc private func dismissSettings() {
        self.dismiss(animated: true, completion: .none)
    }
}

extension RQTarjmatulClassViewController : YTPlayerViewDelegate {
    func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
        playerView.seek(toSeconds: Float(startSecond), allowSeekAhead: true)
        playerView.playVideo()
    }
}

when dismissSettings is called then the pip is also ended instead. dismissSettings dismisses the parent view controller where YTPlayerView is hosted but how can I keep the YTPlayerView in pip mode even when the parent view is dismissed or how the parent view can be collapsed or revived when coming in and out of the PIP?

Another thing is that the app has no control over PIP. The view automatically adds the PIP button when in fullscreen and handles all the PIP-related things. So any insight on this will be good as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@syedabdulsamad and others