1 import UIKit
2 import AVFoundation
3
4 class ViewController:UIViewController {
5
6 override func viewDidLoad() {
7 super.viewDidLoad()
8 // Do any additional setup after loading the view,
typically from a nib.
9 let moviePath =
Bundle.main.path(forResource:“movie”, ofType:“mp4”)
10 let movieURL = URL(fileURLWithPath:moviePath!)
11
12 let avPlayer = AVPlayer(url:movieURL as URL)
13 let avPlayerLayer = AVPlayerLayer(player:avPlayer)
14 avPlayerLayer.frame = self.view.bounds
15 avPlayerLayer.videoGravity =
AVLayerVideoGravityResizeAspectFill
16 self.view.layer.addSublayer(avPlayerLayer)
17
18 avPlayer.play()
19 }
20 }