0

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?

1 Answer 1

0

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.
1
  • Thank you. I'll put my actual code in another answer once I have it figured out ;-) May 15, 2012 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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