How to have video be ready to play in swift

The following code has a video being played. But the video starts immediately when the view controller is launch. When the view controller is launch I would like the user to hit the play button for the video to play. Now the video plays as soon as the view controller is launched.

 let path = NSBundle.mainBundle().pathForResource("x", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
self.moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = self.moviePlayer {
    player.view.frame = CGRect(x: 55, y: 75, width: self.view.frame.size.width/2, height: self.view.frame.size.height / 5)
    player.view.sizeToFit()
    player.scalingMode = MPMovieScalingMode.AspectFit
    player.fullscreen = false
    player.controlStyle = MPMovieControlStyle.Default
    player.movieSourceType = MPMovieSourceType.File
    player.repeatMode = MPMovieRepeatMode.One
    player.play()
    self.view.addSubview(player.view)

The call to player.play() starts your video.
Leaving that out should let the user start the video with the play button.

Have fun!

I tried that out did not work all that does is create a black screen.

player is only valid within that block. Have you tried calling self.moviePlayer.play() from the play button?

It worked thank you. when i click to go to the next view controller the video is still playing. How can I get the video to stop if the view controller page changed?

moviePlayer is still there in the view controller you transitioned away from. Maybe the best approach is to just pause the movie in viewWillDisappear as you transition to the new view controller?

what do you mean in the viewwilldisappear?

viewWillDisappear is a UIViewController method that is called when your view controller is preparing to go off screen. You could override that method and pause your movie there.