inScript, did you find a solution for this? you might want to use something as simple as the if { // do something } else { // do something else } to play them back to back.
To load into the array, create a new plist file (right-click on the directory tree โ Add โ New file) and find the list of properties there, name the list of sound files. Then open this new file, right-click where it says โDictionaryโ by default, go to โValue Typeโ and select โArrayโ ... If you look at the far right of this line, you will see a small search button for 3 bar, click on it to add your first element. Now you add one element at a time "track01", "track02", etc. one per line.
This code is contained in your .h file:
NSArray* soundsList;
This code is in your .m file:
NSString *soundsPath = [[NSBundle mainBundle] pathForResource:@"soundslist" ofType:@"plist"]; soundsList = [[NSArray alloc] initWithContentsOfFile:soundsPath];
Arrays always start with index # 0 ... so if you have 5 tracks, track01 will be index 0, track02 will 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]); }
Everything that does, counts how many elements are in your array (i.e. 5 or 10, or at least a few songs), and objectAtIndex: will return the object by any index number that you send to it.
To play in reverse, you simply 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;
where YOURINDEXNUMBER is any track that you want to play (remember, 0 = track01, 1 = track02, etc.)
If you need help setting up variables in your .h file, let me know and I can go through it. Also, be sure to release theAudio in your dealloc method so that it releases it when the program exits.