How to play video in ios
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