Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>inScript, did you find a solution to this yet? you might want to stick with something simple like an <code>if { // do something } else { // do something else }</code> statement to play them back-to-back.</p> <p>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.</p> <p>This code goes in your .h file:</p> <pre><code>NSArray* soundsList; </code></pre> <p>This code goes in your .m file:</p> <pre><code>NSString *soundsPath = [[NSBundle mainBundle] pathForResource:@"soundslist" ofType:@"plist"]; soundsList = [[NSArray alloc] initWithContentsOfFile:soundsPath]; </code></pre> <p>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:</p> <pre><code>int i = 0; for (i; i &lt;= ([soundsList count] - 1); i++) { NSLog(@"soundsList contains %@", [soundsList objectAtIndex:i]); } </code></pre> <p>All that does is count how many items are in your array (i.e. 5 or 10 or however many songs) and <code>objectAtIndex:</code> will return the object at whatever index number you send into it. </p> <p>For playing back-to-back you'd just put the if-then statement in the <code>audioPlayerDidFinishPlaying</code> method</p> <p>If you want to play the file, you can do:</p> <pre><code>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]; </code></pre> <p>where YOURINDEXNUMBER is whatever track # you wanna play (remember, 0 = track01, 1 = track02, etc)</p> <p>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 <code>theAudio</code> in your dealloc method so it will release it when the program exits.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload