I want to play multiple files by using loop.
I written code below..
Please help me.!!..
soundList = [[NSArray alloc] initWithObjects:@"mySong1.mp3",@"mySong2.mp3",@"mySong3.mp3",@"mySong4.mp3",@"mySong5.mp3",@"mySong6.mp3",@"mySong7.mp3",@"mySong8.mp3",@"mySong9.mp3", nil];
for (i=0; i<=([soundList count] - 1); ) {
while(i<[soundList count]){
NSLog(@"File is : %@",[soundList objectAtIndex:i]);
mediaPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:[soundList objectAtIndex:i] ofType:nil]] error:&error];
[mediaPlayer setDelegate:self];
self.lblCurrentSongName.text = [soundList objectAtIndex:i];
[mediaPlayer prepareToPlay];
i++;
}
}
Please give me suggestion .!!..
I’m going to give you a guideline doing it, but beware it is not tested code. The code you gave will not work for a number of reasons, 1. you don’t call play on avaudioplayer 2. while loop will execute too fast and songs will overlap with each other or since you don’t store the reference to previous avaudioplayer it might create trouble (don’t know exactly)