how to play a video in UIView swift?

后端 未结 3 1888
我寻月下人不归
我寻月下人不归 2021-02-03 10:14

I have a video which I want to download from a server and stream it in a fixed view. I\'ve set a UIView in my storyboard with fixed constraints, and here is what I\'ve done in c

3条回答
  •  庸人自扰
    2021-02-03 10:42

    If you want to use AVPlayerViewController:

    let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    let player = AVPlayer(url: videoURL!)
    let playerViewController = AVPlayerViewController()
    playerViewController.player = player
    self.present(playerViewController, animated: true) {
        playerViewController.player!.play()
    }
    

    For AVPlayer:

    let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    let player = AVPlayer(url: videoURL!)
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = self.view.bounds
    self.view.layer.addSublayer(playerLayer)
    player.play()
    

提交回复
热议问题