inScript, did you find a solution to this yet? you might want to stick with something simple like an if { // do something } else { // do something else }
statement to play them back-to-back.
For loading into an array, create a new plist file (right click on directory tree -> Add -> New File" and find a property list in there; name the file soundslist. Next open that new file, right click on it where it says "Dictionary" by default, go down to "Value Type" and select "Array"... If you look to the far right of that line, you'll see a little 3-bar looking button, click that to add your first item. Now you add one item at a time, "track01", "track02" etc... one per line.
This code goes in your .h file:
NSArray* soundsList;
This code goes in your .m file:
NSString *soundsPath = [[NSBundle mainBundle] pathForResource:@"soundslist" ofType:@"plist"];
soundsList = [[NSArray alloc] initWithContentsOfFile:soundsPath];
Arrays always start at index # 0... so if you have 5 tracks, track01 would be index 0, track02 would be index 1, and so on. If you want to quickly poll your array to see what's in it, you can add this bit of code:
int i = 0;
for (i; i <= ([soundsList count] - 1); i++) {
NSLog(@"soundsList contains %@", [soundsList objectAtIndex:i]);
}
All that does is count how many items are in your array (i.e. 5 or 10 or however many songs) and objectAtIndex:
will return the object at whatever index number you send into it.
For playing back-to-back you'd just put the if-then statement in the audioPlayerDidFinishPlaying
method
If you want to play the file, you can do:
NSString* filename = [soundsList objectAtIndex:YOURINDEXNUMBER];
NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"mp3"];
AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
self.theAudio = newAudio; // automatically retain audio and dealloc old file if new file is loaded
[newAudio release]; // release the audio safely
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio setNumberOfLoops:0];
[theAudio play];
where YOURINDEXNUMBER is whatever track # you wanna play (remember, 0 = track01, 1 = track02, etc)
If you need help setting up the variables in your .h file, let me know and I can walk you through it. Also, remember to release theAudio
in your dealloc method so it will release it when the program exits.