40media 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




how to remove subviews from scrollview?

1:



iPhone PHP integration
First, create the array of your different sounds and a variable to hold the current index:.
does using try catch block in xcode show error on real device?
NSArray *sounds = [[NSArray alloc] initWithObjects:@"0.wav", @"1.wav", nil]; // add all your files here NSUInteger currentSound = 0; 
Then, when you handle your button tapped event, go to the next sound, and play it.


for- loop in background thread accesses each index more than once — iPhone dev
If it's at the end of your NSArray, go back to index 0:.
Update coordinate property of MKAnnotation on parent viewcontroller after Touch End event?
currentSound++; if (currentSound >= [sounds count]) {     currentSound = 0; }  // play the sound. 


Memory Management Question in Objective C
Just call your own method here [self playSoundWithFilename:[sounds objectAtIndex:currentSound]];


UITableView frame height animation glitch


72 out of 100 based on 17 user ratings 392 reviews