call video play code on action , not on viewdidload

import AVFoundation
import AVKit

class VideoPlayerViewController: UIViewController, AVPlayerViewControllerDelegate {

    var playerController = AVPlayerViewController()
    override func viewDidLoad() {

        // Do any additional setup after loading the view.
@IBAction func btnPressed(_ sender: Any) {
       guard let url = URL(string: "")else {return}
        let player = AVPlayer(url: url)
        playerController = AVPlayerViewController()
        playerController.player = player
        playerController.allowsPictureInPicturePlayback = true
        playerController.delegate = self
    self.present(playerController , animated: true, completion: nil)
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter