Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

You could provide each view controller with a property that is your movie store. Then you can configure each view controller to use the same object:

  • if it appears as the result of a transition from a different view controller, the previous controller can pass its movie store to the new controller.
  • the first view controller can receive the configured movie store from either its NIB file or from the app delegate, which is ultimately responsible for configuring the window and therefore for getting the first view controller ready to be displayed.
share|improve this answer
    
Thank you. I'll put my actual code in another answer once I have it figured out ;-) –  Thunder Rabbit May 15 '12 at 20:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.