prajna
prajna

Reputation: 1637

Loading MPMoviePlayerViewController with transparent background in Swift?

I am using the MPMoviePlayerViewController in Swift (iOS 8.1) and am using the code as per the answer at How to play a local video with Swift?) and this all works fine.

This code is as follows:

    let path = NSBundle.mainBundle().pathForResource("movie",     ofType:"m4v")
    let url = NSURL.fileURLWithPath(path!)
    moviePlayer = MPMoviePlayerController(contentURL: url)

    if let player = moviePlayer {
        player.view.frame = self.animationImage.frame
        player.backgroundView.backgroundColor = UIColor.clearColor()
        player.view.backgroundColor = UIColor.clearColor()

        for subView in player.view.subviews  {
            subView.backgroundColor = UIColor.clearColor()
        }

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

But am trying to make the background of the movie player transparent. I have found answers for using Objective-C but I am running into an error on compiling. The code I currently have is:

player.backgroundView.backgroundColor = UIColor.clearColor()
player.view.backgroundColor = UIColor.clearColor()

for subView in player.view.subviews  {
     subView.backgroundColor = UIColor.clearColor()
} 

The compile error occurs on the subView.backgroundColor = UIColor.clearColor() line. The error is:

'@lvalue $T4' is not identical to 'CGColor!!'

Any help as to what I am doing wrong here would be very much appreciated.

Upvotes: 2

Views: 995

Answers (1)

gabbler
gabbler

Reputation: 13766

I think you may want to specify that subView is of type UIView.

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

Upvotes: 3

Related Questions