Become nil Referring to YTPlayer from a different view
<p>I want to control the video player of the video view from the screen transition destination.</p>

<p><img src="https://i.stack.imgur.com/qfITt.png" alt="I want to play a video by tapping the cell"></p>

<p>I want to play a video by tapping the cell</p>

<p>Try to</p>

<p>// Select(Tap) to cell</p>

<pre><code>override func tableView(_ table: UITableView,didSelectRowAt indexPath: IndexPath) {

          let video = ViewController()

          video.playerView.playVideo()

    }
</code></pre>

<p>But fatal error: unexpectedly found nil while unwrapping an Optional value</p>

<p><img src="https://i.stack.imgur.com/31hqL.png" alt="Error"></p>

<p>Append:</p>

<p>I tried to use YTPlayer from <a href="https://github.com/youtube/youtube-ios-player-helper" rel="nofollow noreferrer">https://github.com/youtube/youtube-ios-player-helper</a></p>

<p>But I did not understand how to write in your code "YTPlayer".</p>

<p>YTPlayer doesn't have YTPlayer(exist YTPlayerView) and YTPlayerLayer.</p>

<p>My viewcontoller's code here</p>

<pre><code>import UIKit
import youtube_ios_player_helper
import AVFoundation

class ViewController: UIViewController, YTPlayerViewDelegate{

@IBOutlet var playerView: YTPlayerView!

var appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate



override func viewDidLoad() {
    super.viewDidLoad()

    self.playerView.delegate = self

    self.playerView.sizeToFit()



    let vars = ["playsinline": 1, "controls": 2, "showinfo": 0, "origin":"https://www.google.com"] as [String : Any]

    if self.appDelegate.selectMV == ""
    {
        print("Not Load",self.appDelegate.selectMV)
    }
    else
    {
        print("Load",self.appDelegate.selectMV)
        playerView.load(withVideoId: self.appDelegate.selectMV, playerVars: vars)
    }

    let audioSession = AVAudioSession.sharedInstance()

    do {

        try audioSession.setCategory(AVAudioSessionCategoryPlayback)

    }

    catch {

        print("")

    }


}

func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
    playerView.playVideo()
}

func play() {
    print("Push! play")
    //Error playerView nil 
    playerView.load(withVideoId: self.appDelegate.selectMV)
    playerView.playVideo()
    }

}
</code></pre>