我想在出现alertview时播放声音文件并连续播放,直到用户单击ok或cancel。我该怎么做?

最佳答案

正如Zoul所说,您可以在调用[myAlert show]时设置并播放声音,并在警报 View 回调中取消声音。您的代码将如下所示:

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

关于objective-c - 当Alertview出现iPhone SDK时如何播放声音?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1617926/

10-13 04:47