Pregunta

Quiero reproducir un archivo de sonido cuando aparece la vista de alerta y se reproduce continuamente hasta que el usuario haga clic en Aceptar o Cancelar. ¿Cómo hago esto?

¿Fue útil?

Solución

Como dice Zoul, configura y reproduce su sonido al llamar a [myAlert show] y cancela el sonido en la devolución de llamada de la vista de alerta. Su código tendrá un aspecto similar al siguiente:

  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];

Otros consejos

Como ya llama al método show para mostrar el cuadro de diálogo, ¿por qué no simplemente comienza a reproducir el sonido allí y se detiene en

scroll top