I've got three nib files in my project, each of which is driven by its own class (.h and .m files). Each nib has a stylized design with a full screen background image and a few overlay images acting as buttons. Each button has its own button-click sound, and most of the buttons on each nib file will play a different video per button.
To play the videos, each of my three .m files have a couple of methods similar to this:
-(IBAction) videoButtonClicked: (id)sender{
if([sender tag] == 1) {
AudioServicesPlaySystemSound (buttonClick1);
[self loadMoviePlayer:[[NSBundle mainBundle] pathForResource:@"Video 1" ofType:@"mov"]];
} else if ([sender tag] == 2) {
AudioServicesPlaySystemSound (buttonClick2);
[self loadMoviePlayer:[[NSBundle mainBundle] pathForResource:@"Video 2" ofType:@"mov"]];
} else if ([sender tag] == 3) {
AudioServicesPlaySystemSound (buttonClick3);
[self loadMoviePlayer:[[NSBundle mainBundle] pathForResource:@"Video 3" ofType:@"mov"]];
} else if ([sender tag] == 4) {
AudioServicesPlaySystemSound (buttonClick4);
[self loadMoviePlayer:[[NSBundle mainBundle] pathForResource:@"Video 4" ofType:@"mov"]];
}
}
- (void)loadMoviePlayer:(NSString*) movieURL
{
// Play movie from the bundle
NSURL *url = [NSURL fileURLWithPath:movieURL];
player = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
}
My code works now because the videos are embedded in my resources folder.
However, together, the videos are too big to be bundled with the app and downloaded from the App Store.
I'll therefore have the app download them from a server, so I want to create one video-management class to keep track of which videos have been downloaded. I think I should have one instance of the object, but then how can my three controllers talk to the one instance?
I am pretty sure if I have one class that loads the correct .nib file, I can have that one instance talk to my one video-management instance.
But would I be unnecessarily wasting memory by loading all three nibs at once?