Maple
Maple

Reputation: 99

How to get video player to NOT auto play while using MPMoviePlayerController

I'm trying to code a video into my iPhone app and the code below works perfectly but the only thing is that I rather the video not automatically start playing when the user opens the page. I want them to be able to push the play button. The code below is located in my viewcontroller.m file.

(void)viewDidLoad
{
NSString *url = [[NSBundle mainBundle] pathForResource:@"77860_00_01_MM02_welcome" 
ofType:@"mov"];
player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];

player.view.frame = CGRectMake(10, 235, 150, 125);
[self.view addSubview:player.view];

[player play];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[player play];
}

Upvotes: 1

Views: 1992

Answers (2)

Maple
Maple

Reputation: 99

Never mind, I figured it out. I just added [player prepareToPlay] under player.shouldAutoplay = NO

Upvotes: 4

David Moore
David Moore

Reputation: 51

Don't put it in your viewDidLoad. Just create an IBAction them link it up to your trigger button.

Upvotes: 0

Related Questions