Implementing video view in the Storyboard

前端 未结 4 1813
别跟我提以往
别跟我提以往 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:35

    There is no object in the original library that performs video viewing function. But you can import the MediaPlayer framework in your project and add it programmatically.

    Here is a Swift example

    import MediaPlayer
    
    class Step1ViewController: UIViewController {
    
    var moviePlayer: MPMoviePlayerController?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        playVideo()
    }
    
    func playVideo() {
    
        let videoView = UIView(frame: CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.width, self.view.bounds.height))
    
        let pathToEx1 = NSBundle.mainBundle().pathForResource("myVideoFile", ofType: "mp4")
        let pathURL = NSURL.fileURLWithPath(pathToEx1!)
        moviePlayer = MPMoviePlayerController(contentURL: pathURL)
        if let player = moviePlayer {
            player.view.frame = videoView.bounds
            player.prepareToPlay()
            player.scalingMode = .AspectFill
            videoView.addSubview(player.view)
        }
    
        self.view.addSubview(videoView)
    }
    

    }

    As for further customisations and app notifications it has a bunch of in-build possibilities. So check it out.

提交回复
热议问题