Domanda

Voglio riprodurre un file audio quando viene visualizzato alertview e viene riprodotto continuamente fino a quando l'utente non fa clic su OK o Annulla. Come faccio?

È stato utile?

Soluzione

Come dice Zoul, imposti e riproduci il tuo suono mentre chiami [myAlert show] e annulli il suono nella richiamata della vista di avviso. Il tuo codice sarà simile a questo:

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

Altri suggerimenti

Dato che chiami già il metodo show per visualizzare la finestra di dialogo, perché non devi semplicemente iniziare a riprodurre il suono lì e fermarti nello sviluppatore

scroll top