How do I make a button play sounds in a certain order using an array?


How do I make a button play sounds in a certain order using an array?



I'm coding in Objective-C for the iPhone and I am trying create an array that plays a series of sounds. For example the first time I press the button I want it play sound "0.wav", but the second time I want it to play "1.wav", then "2.wav", "3.wav", etc. Then when I've played a total of 14 sounds (up to "13.wav") I want the loop to start over playing with 0.wav. I've looked around Google and the Apple development documentation for almost 4 days without much luck. So if someone could help me generate a code for this that would be greatly appreciated and if you wouldn't mind could you attempt to explain the code briefly so that I can learn what each part does.

Thank you, Joey


EDIT

Okay I've gotten the Array part down (thanks to Thomas) however neither of us are sure how to implement the soundID from the array to the action where I play the sound and how to play that sound. I used the format Thomas used for his array below if that helps you with your answer.

Thanks, Joey


Renew Provisioning Profile

1:

[iPhone SDK] [Newbie] UITextView textViewDidChange will not be called?
First, create the array of your different sounds and a variable to hold the current index:. conflict between JQuery slider and iui (iphone)
NSArray *sounds = [[NSArray alloc] initWithObjects:@"0.wav", @"1.wav", nil]; // add all your files here NSUInteger currentSound = 0; 
Then, when you handle your although ton tapped event, go to the next sound, and play it. Anyone know how to slide in a UIDatePicker like keyboard?If it's at the end of your NSArray, go back to index 0:. Managing data for UITableViews
currentSound++; if (currentSound >= [sounds count]) {     currentSound = 0; }  // play the sound. How to get a C method to accept UIImage parameter?Just call your own method here [self playSoundWithFilename:[sounds objectAtIndex:currentSound]]; 
how to release uiview added as subview in scrollview?

52 out of 100 based on 67 user ratings 462 reviews