Development record of developer who study hard everyday.

, ,

How to play video in ios

 How to play video in ios

ios develop blog

This post introduce how to play video in ios.

One way is to play local video file and the other way is to play video with url.

Let's go


1. Video file

let filePath: String? = Bundle.main.path(forResource: "FastTyping", ofType: "mp4")

        let url = NSURL(fileURLWithPath: filePath!)

        

        let playerController = AVPlayerViewController()

        

        let player = AVPlayer(url: url as URL)

        playerController.player = player

        

        self.present(playerController, animated: true) {

            player.play()

        }


2. Video url

let url = NSURL(string: "https://dl.dropboxusercontent.com/s/e38auz050w2mvud/Fireworks.mp4")!

        

        let playerController = AVPlayerViewController()

        

        let player = AVPlayer(url: url as URL)

        playerController.player = player

        

        self.present(playerController, animated: true) {

            player.play()

        }


👇 You can see full code in my git.

https://github.com/antwhale/SampleMoviePlayer_ios.git


Share:

댓글 없음:

댓글 쓰기