youtube-ios-player-helper
youtube-ios-player-helper copied to clipboard
Collapse the parent view of YTPlayerView when picture in Picture is enabled
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.