Reputation: 2115
I have a local .mp4 video that I would like to add as a background video. I've created a function:
func playVideo() {
let path = NSBundle.mainBundle().pathForResource("dronefootagecompressed", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
self.moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = self.moviePlayer {
player.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
player.view.sizeToFit()
player.scalingMode = MPMovieScalingMode.Fill
player.fullscreen = true
player.controlStyle = MPMovieControlStyle.None
player.movieSourceType = MPMovieSourceType.File
player.repeatMode = MPMovieRepeatMode.One
player.play()
self.view.addSubview(player.view)
}
}
which is then called in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
playVideo()
}
The video is showing up, but it seems like it's covering everything else (text labels, titles, everything), or so I assume it is. Can I make the video be in the background (if that even is the issue)?
Thanks.
EDIT:
When I call playVideo()
in viewDidAppear
, the video shows up for about 2 seconds before going to a black background. The buttons are still visible. Is the video not loading properly?
Upvotes: 0
Views: 258
Reputation: 1252
i think putting it in viewDidAppear() method will solve the thing
Upvotes: 1