-6

I developed an app for kids and it includes some practice tests so when the answer is correct I wrote code to display alert "correct". I want code for when displaying the alert "correct". It should also come along with voice.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103

1 Answers1

2

Get the path of the audio and then start the audio with the alertview and then you can stop it when the button is pressed.Something like this..

 NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/yourAudio.mp3", [[NSBundle mainBundle] resourcePath]]];

   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 1;
[audioPlayer play];
[alert show]; 

Stop the audio here.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 if (buttonIndex==0) {

 [audioPlayer stop];

}

Note : Add AVAudio framework and if youdon't want to play the audio untill the button of UIAlertView is clicked then set audioPlayer.numberOfLoops = -1;

mrunmaya
  • 41
  • 6