Talon
Talon

Reputation: 4995

How to play a movie on iOS

So I created a view that has a button in it that will play the movie.

Here is the action for that button:

- (IBAction)playMovie {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"sample_iPod" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
}

However when I test the App and try to play the video the screen stays blank and in the log it shows this:

[Switching to process 9333 thread 0x13c03]

Any Idea what's up?

Thanks

Upvotes: 3

Views: 1001

Answers (1)

Rayfleck
Rayfleck

Reputation: 12106

You need to set the bounds of the player, and add the player's view to self.view:

 [theMovie.view setFrame: self.view.bounds];  // player's frame must match parent's
 [self.view addSubview: theMovie.view];

Upvotes: 4

Related Questions