Video Player

PHOTO EMBED

Tue Aug 30 2022 07:54:18 GMT+0000 (UTC)

Saved by @hasnat #ios #swift #video #player

call video play code on action , not on viewdidload

import AVFoundation
import AVKit

class VideoPlayerViewController: UIViewController, AVPlayerViewControllerDelegate {

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

        // Do any additional setup after loading the view.
    }
  
@IBAction func btnPressed(_ sender: Any) {
       guard let url = URL(string: "https://firebasestorage.googleapis.com/v0/b/kreative-app.appspot.com/o/FileMessage%2F1661341223.mp4?alt=media&token=e8ca21b2-8ea9-44bc-a28f-85598395081c")else {return}
        let player = AVPlayer(url: url)
        
        playerController = AVPlayerViewController()
     
        playerController.player = player
        playerController.allowsPictureInPicturePlayback = true
        playerController.delegate = self
        playerController.player?.play()
    self.present(playerController , animated: true, completion: nil)
    }
content_copyCOPY