Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

MPMoviePlayer using Swift for Ribbit app

I'm trying to learn Swift by modifying the Ribbit app to Swift code. I want to allow the user to preview the video they take before they send it to their friends, but I can't get an MPMoviePlayer to play a preview of the captured video file. I've tried to get it to work a number of different ways, but here is my most recent code. It seems pretty straightforward, but for whatever reason the MPMoviePlayer won't appear or play.

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
    {
        videoUrl = info[UIImagePickerControllerMediaURL] as NSURL

        var player = MPMoviePlayerController(contentURL: videoUrl)
        player.prepareToPlay()
        self.view.addSubView(player.view)
        player.setFullscreen(true, animated: true)
        player.play()
    }

Edit

After some further tinkering, I think the problem lies within the self.view.addSubView(player.view) method. The imagePicker is on a custom overlay nib, and then I'm trying to put the moviePlayer on top of that I believe? Still not sure what the solution is, but we're getting there.