PDA

View Full Version : iPad play video when button tapped




Michael H
Jul 20, 2010, 05:53 PM
I am trying to accomplish on an iPad having a Menu view that has a button and when you tap button .mov clip will play and when it ends Menu view will re-appear. When I start application the Video view appears not the Menu view. You can tap the play button and the video play just fine and at end a blank whit screen appears. Here are the .h & .m files. Please help.

.h

#import <UIKit/UIKit.h>

#import <MediaPlayer/MediaPlayer.h>

@interface mainMenuViewController : UIViewController {

MPMoviePlayerController *playerViewController;
}

- (IBAction) playVideo;

@end

.m

#import "mainMenuViewController.h"

@implementation mainMenuViewController



- (void)viewDidLoad {

NSString *url = [[NSBundle mainBundle] pathForResource:@"BeachCompilation" ofType:@"mov"];
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];


[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];

WARNING - Local declaration of ‘playerViewContoller’ hides instance variable


[self.view addSubview:playerViewController.view];

WARNING - Local declaration of ‘playerViewContoller’ hides instance variable

[super viewDidLoad];

}

- (IBAction) goToBeachMenu: (NSURL *) url {

//NSLog(@"button works");


MPMoviePlayerController *player = [playerViewController moviePlayer];

WARNING - ‘MpmoviePlayerController’ may not respond to ‘-moviePlyer’

[player play];

}



dejo
Jul 20, 2010, 08:18 PM
1. Name the local playerViewController variable from the viewDidLoad something different than the instance variable of the same name.

2. You sure you want to add the subView in viewDidLoad and not in the button's action?

3. What does the code for the movieFinishedCallback: look like?