Swift. Display video with transparent background

451 Views Asked by At

I have my main view with some different categories, and when a player completes 100% of a category I want confetti to rain down.

I have the confetti as a video (Only the confetti is visible, the background is transparent) and I'm trying to display the video on my view with MPMoviePlayer like so:

let path = NSBundle.mainBundle().pathForResource("Confetti", ofType:"mov")
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.bounds.height * 1.2 * (1920/1080), height: self.view.bounds.height * 1.2)
    player.view.frame.origin.x = 0 - (player.view.frame.width - self.view.bounds.width) / 2
    player.backgroundView.backgroundColor = UIColor.clearColor()
    player.view.backgroundColor = UIColor.clearColor()

    for subView in self.moviePlayer!.view.subviews as [UIView] {
        subView.backgroundColor = UIColor.clearColor()
    }

    player.prepareToPlay()
    player.scalingMode = .AspectFill
    player.controlStyle = .None
    self.view.addSubview(player.view)
}

But it doesn't work, this is what shows:

MPMoviePlayer

How do I make it work, or is there some other way that would be better to do this?

0

There are 0 best solutions below