Implementing video view in the Storyboard

前端 未结 4 1824
别跟我提以往
别跟我提以往 2021-02-06 13:49

I want to build simple video app thats views a video form youtube links thats users add. I didn\'t find \"VideoView\" I mean If image view is for image what is UIView for video

4条回答
  •  灰色年华
    2021-02-06 14:21

    import AVFoundation
    import AVKit
    
    class ViewController: UIViewController { 
        var player = AVPlayer()
        var playerController = AVPlayerViewController()
    
        func playVideo() {     
            let videoURL = NSURL(string: videoUrl)
            player = AVPlayer(url: videoURL! as URL)
            let playerController = AVPlayerViewController()
            playerController.player = player
            self.addChildViewController(playerController)
    
        // Add your view Frame
             playerController.view.frame = self.view.frame
    
       // Add subview in your view
             self.view.addSubview(playerController.view)
    
       player.play()
     }
    
     func stopVideo() {
        player.pause()
     }
    }
    

提交回复
热议问题