2

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.

Community
  • 1
  • 1
prajna
  • 1,629
  • 1
  • 17
  • 18

1 Answers1

3

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()
}
gabbler
  • 13,626
  • 4
  • 32
  • 44
  • 1
    Brilliant! Thanks gabbler. You answered my question but unfortunately I still can't get the background of the animation to be transparent. Thanks. – prajna Jan 24 '15 at 04:28
  • Using clearColor should be enough, if your `self.view` has a background color like red color, with `scalingMode = .AspectFit`, you will see that red color when you play the movie. You can always set your `player.view`'s border color and border width to see whether your movie is filled in its frame. – gabbler Jan 24 '15 at 04:44