Question

i want to play a sound file when alertview appears and plays continuously till user clicks on ok or cancel.how do i do this?

Was it helpful?

Solution

As Zoul says, you set-up and play your sound as you call [myAlert show] and cancel the sound in the alert view callback. Your code will look something like this:

  AVAudioPlayer *myPlayer;

  // ...

  // create an alert...

  NSError *error;
  myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mySoundFileURL error:&error];
  // handle errors here.
  [myPlayer setNumberOfLoops:-1];  // repeat forever
  [myPlayer play];
  [myAlert show];

  // ...

  // in alert callback.
  [myPlayer stop];
  [myPlayer release];

OTHER TIPS

As you already call the show method to display the dialog, why don’t you simply start playing the sound there and stop in the alert view callback? For the sound itself you can use AVAudioPlayer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top