Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f6a3ea0)

I am trying to use AVPlayerView Controller But when i try to play the video its crash

This is my Code

`import UIKit import AVKit import SwiftyJSON import Alamofire import EffyIosFramework

class VideoViewController: UIViewController, AVPlayerViewControllerDelegate {

var player : AVPlayer!
var vc = AVPlayerViewController()
var isVideoPlaying = false
var instance = VideoViewController()

//View Did Load
override func viewDidLoad() {
    super.viewDidLoad()

    vc.delegate = self
}

//Play Video
func playVideo(url: URL) {

    player = AVPlayer(url: url)
    vc.player = player
    player.automaticallyWaitsToMinimizeStalling = false
    vc.delegate = self
    vc.showsPlaybackControls = false
    vc.videoGravity = AVLayerVideoGravity.resizeAspectFill

    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.opacity = 0
    self.isVideoPlaying = true
    self.vc.player?.play()
    DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.2) {
        self.vc.view.frame = self.view.window!.bounds
        self.vc.view.backgroundColor = .clear
        DispatchQueue.main.async {
            self.vc.view.addSubview(self.view)
        }
        self.view.window?.addSubview(self.vc.view)
    }
}

}

I tested the code, no such error.

Which version of Xcode ?

A question: why do you create an instance of the class inside the class ?

     var instance = VideoViewController()

version of Xcode : 13 A question: why do you create an instance of the class inside the class ?      var instance = VideoViewController()

ANS: BCS i am accesing playVideo() function in another viewcontroller on onclickbutton the video has to play

@IBAction func VideoPlay(_ sender: AnyObject)
  {

    let mainDirectory : String? = AppUtils.createFolder(directoryName:
"Temp")

    let subDirctory : String? =
AppUtils.createSubFolder(mainDirectoryName: mainDirectory!,
subDirectoryName: String(AppConstants.VIDEO_FIELD_ID))

    let subFolderData : [String]? = AppUtils.getDataFromFolder(path:
subDirctory!)

    let name: String =
AppPreference.getInstance().getString(AppConstants.VIDEO, 
defaultvalue: "")

   
    let streamingURL : URL = NSURL(string:
subDirctory!.appending("/"+name)) as! URL

 VideoViewController().instance.playVideo(url: streamingURL)



  }
code-block
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f6a3ea0)
 
 
Q