I've spent more or less most of they day working out how to play an audio file after another audio file has completed playing.
I have tried the audioPlayerDidFinishPlaying which I had limited success with as it played the second audio file when other audio files played. So it played when any audio file played and I wanted it to only play when a certain audio file was played. I also found that on some devices the audio got stuck in a loop so it treated the file that was triggered to play in the audioPlayerDidFinishPlaying and played the file again.
Anyway it has grinded me down all day and I'm shattered.
Anyway I have found a solution and it works perfectly for what I wanted but I am getting a warning that I can not work out how to resolve.
NSArray *theSoundArray = [NSArray arrayWithObjects:@"dog-00-voice",@"dog-00",nil];
int totalSoundsInQueue = [theSoundArray count];
for (int i=0; i < totalSoundsInQueue; i ) {
NSLog(@"%d", i);
NSString *sound = [theSoundArray objectAtIndex:i];
// Wait until the audio player is not playing anything
while(![arraySounds isPlaying]){
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:sound ofType:@"mp3"]] error:NULL];
self.arraySounds = player;
[arraySounds setVolume:1.0f];
[arraySounds play];
i++;
NSLog(@"%d", i);
}
}
This works but I am getting a warning for the i at the end of the for loop line. "Expression result unused'.
Can anyone help me either resolve this or advise me on how I can get audioPlayerDidFinishPlaying to work as explained above.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire