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.
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()
}