Last active
November 9, 2016 13:27
-
-
Save michaelevensen/35af0d3794018310e8e23753ad99ecd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load video | |
// Note: Needs to be a supported AVPlayer format, in this case MP4 (could also be M4V etc.) | |
if let filePath = Bundle.main.path(forResource: "video", ofType: "mp4") { | |
// url | |
let fileUrl = URL(fileURLWithPath: filePath) | |
// Player | |
let player = AVPlayer(url: fileUrl) | |
// video layer | |
let videoLayer = AVPlayerLayer(player: player) | |
videoLayer.frame = self.view.bounds | |
videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill | |
let videoView = UIView(frame: self.view.frame) | |
videoView.layer.addSublayer(videoLayer) | |
// Add video to backgroundView | |
self.view.addSubview(videoView) | |
self.view.sendSubview(toBack: videoView) | |
// play | |
player.play() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment