I'm trying to show a movie that was captured with UIImagePickerController inside a generic UIView container but it's not working. The container view is visible but no video is shown in the container view.
I've put my code inside didFinishPickingMediaWithInfo
and this is what I've got so far. The capturing is working and I get a valid movie url but I'm not sure if I can/should just add the moviePlayer.view
as a subview to the container and if it will be sized correctly. I was hoping the scalingMode = .AspectFill
would take care of that.
@IBOutlet weak var videoContainer: UIView!
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
dismissViewControllerAnimated(true, completion: nil)
if let movieUrl = info[UIImagePickerControllerMediaURL] as? NSURL {
println("Movie url found: \(movieUrl)")
let moviePlayer = MPMoviePlayerController(contentURL: movieUrl)
moviePlayer.controlStyle = MPMovieControlStyle.None
moviePlayer.prepareToPlay()
moviePlayer.scalingMode = .AspectFill
videoContainer.addSubview(moviePlayer.view)
moviePlayer.play()
}
}
The Documentation says :
player's frame must match parent's
I can't see any line of code where you try to set the players view frame. The scaling mode has nothing to do with the frame of the view. It is used to define how the video content is actually scaled inside the view