AVAudioPlayer* theAudio=[[AVAudioPlayer alloc]initWithContentsofURL: [NSURL arrayURLWithPath:array] error:NULL];
it should be:
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc]initWithContentsofURL: [NSURL URLWithString:[array objectAtIndex:11]] error:NULL];
therefore, the number "11" is a random file path. To get random, you can use this:
int randomNumber = random()%1000; // random number between 0 and 1000
and then use randomNumberinstead11
, , , . , , 999 1000 , 1.
//EDIT: :
-(IBAction)playSound {
NSArray *array = [[NSBundle mainBundle] pathsForResourcesOfType:@".mp3" inDirectory:@"Resources"];
int rndm = arc4random() % [array count];
if (rndm<0) rndm*=-1;
NSString *randomPath = [array objectAtIndex:rndm];
AVAudioPlayer* theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: randomPath] error: NULL;
theAudio.delegate = self;
[theAudio play];
}
user207616