views:

56

answers:

1

Edit: if you come across this and want to know how I eventually solved it I gave up on that code below eventually and did this:

-(void)playMovieAtURL:(NSURL*)theURL{
    mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];

    [self presentMoviePlayerViewControllerAnimated:mediaPlayer];
    mediaPlayer.view.backgroundColor = [UIColor blackColor];

}

Original post:

This is my code - I took it off the apple site so shouldn't be a problem.

It runs in a UITableViewController on the didSelectRowAtIndexPath method.

When you select the row the video starts playing - the sound outputs at least - but there's no picture. Any idea why this is? I have included the framework.

The video is one off the apple website (a facetime video) that I used for testing.

 -(void)playMovieAtURL:(NSURL*)theURL{



        MPMoviePlayerController* theMovie =

        [[MPMoviePlayerController alloc] initWithContentURL: theURL];



        theMovie.scalingMode = MPMovieScalingModeAspectFill;

        theMovie.controlStyle = MPMovieControlStyleNone;



        // Register for the playback finished notification

        [[NSNotificationCenter defaultCenter]

         addObserver: self

         selector: @selector(myMovieFinishedCallback:)

         name: MPMoviePlayerPlaybackDidFinishNotification

         object: theMovie];



        // Movie playback is asynchronous, so this method returns immediately.

        [theMovie play];

    }
+1  A: 

The behaviour of MPMoviePlayerController changed in OS 3.2 - you need to explicitly add the movie player's view to your view hierarchy now - using something like:

[aView addSubview:moviePlayerController.view];
moviePlayerController.view.frame = aView.frame;

Alternatively you can use an MPMoviePlayerViewController (new in 3.2) to manage the view.

If you're targetting both pre- and post-3.2 devices (e.g. iOS 3.1 and 4.0) then you'll need some conditional code to determine the OS the code is running on and handle accordingly. I've used this in previous projects:

if ([moviePlayerController respondsToSelector:@selector(setFullscreen:animated:)]) {
    // Running on OS 3.2 or above
    // Code to add to a view here...
}
Simon Whitaker
used MPMoviePlayerViewController now... much much simpler. :) thank you.
Thomas Clayson
Great stuff! Glad you got it working. :)
Simon Whitaker