PDA

View Full Version : [Resolved] Help With Pop-Up Buttons




Demon5263
May 15, 2011, 08:56 PM
Hello, I am trying to program audio to play in a app that I am making, in which you use a pop-up button to select which audio file will play. The only problem is that when the app loads, song1 plays, and when you press "play" (which plays the audio selected in the pop-up menu) it only plays song2, regardless of your choice. I am just starting to learn how pop-up buttons work, but if someone could tell me whats wrong so I can fix it, it would be very much appreciated.

@implementation MusicBoardVideoController

int movie;
int moviePathStr;

- (void)awakeFromNib
{
NSString* moviePathStr = [[NSBundle mainBundle] pathForResource:@"songone" ofType:@"mp3"];
QTMovie* movie = [[QTMovie alloc] initWithFile:moviePathStr error:nil];
if (movie != nil)
{
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieEditableAttribute];
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieLoopsAttribute];
[movie setAttribute:[NSNumber numberWithFloat:5.0] forKey:QTMovieVolumeAttribute];

[(QTMovieView*)[self view] setMovie:movie];
[(QTMovieView*)[self view] setPreservesAspectRatio:YES];
[[(QTMovieView*)[self view] movie] play];

[movie release];
}
}

- (IBAction)pause:(id)sender {
[audioView pause:self];
}

- (IBAction)play:(id)sender {

movie = [musicPopup selectedTag];
switch (movie) {

case 0:
{
{
NSString* moviePathStr = [[NSBundle mainBundle] pathForResource:@"songone" ofType:@"mp3"];
QTMovie* movie = [[QTMovie alloc] initWithFile:moviePathStr error:nil];
if (movie != nil)
{
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieEditableAttribute];
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieLoopsAttribute];
[movie setAttribute:[NSNumber numberWithFloat:5.0] forKey:QTMovieVolumeAttribute];

[(QTMovieView*)[self view] setMovie:movie];
[(QTMovieView*)[self view] setPreservesAspectRatio:YES];
[[(QTMovieView*)[self view] movie] play];

[movie release];
}
}
}

case 1:
{
{
NSString* moviePathStr = [[NSBundle mainBundle] pathForResource:@"songtwo" ofType:@"mp3"];
QTMovie* movie = [[QTMovie alloc] initWithFile:moviePathStr error:nil];
if (movie != nil)
{
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieEditableAttribute];
[movie setAttribute:[NSNumber numberWithBool:NO] forKey:QTMovieLoopsAttribute];
[movie setAttribute:[NSNumber numberWithFloat:5.0] forKey:QTMovieVolumeAttribute];

[(QTMovieView*)[self view] setMovie:movie];
[(QTMovieView*)[self view] setPreservesAspectRatio:YES];
[[(QTMovieView*)[self view] movie] play];

[movie release];
}
}
}
}

}
@end

Sorry for posting the whole code, I thought it may be easier to figure out the problem.



chown33
May 15, 2011, 09:14 PM
In a switch statement, a case label runs into the next following case label unless there's a break.

Your case 0: has no break, so it's running into case 1:, so only that audio/movie plays.

Put a break statement after the last } of the case 0: block.

If none of that makes sense, you need to review how case works in switch statements.

You have an excess of { }'s. You don't need to bracket a bracketed block with an additional set of brackets. This:
{
{
something;
}
}
is the same as this:
{
something;
}


By the way, you did the right thing by posting all the code, and by enclosing it in CODE tags.

Demon5263
May 15, 2011, 09:34 PM
Thank you very much, I thought I put in the break; but I guess I took that out along the way.

Thanks for the tip on the brackets.