【问题标题】:how to display an alert along with voice? [closed]如何显示警报和语音? [关闭]
【发布时间】:2013-09-17 06:54:06
【问题描述】:

我为孩子们开发了一个应用程序,其中包含一些练习测试,因此当答案正确时,我编写了代码以显示警报 "correct"。我想要显示警报"correct" 时的代码。它也应该伴随着声音。

【问题讨论】:

标签: mobile-application audio-player


【解决方案1】:

获取音频的路径,然后使用警报视图启动音频,然后在按下按钮时可以停止它。像这样的东西..

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

在此处停止音频。

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

 [audioPlayer stop];

}

注意:添加 AVAudio 框架,如果你不想在 UIAlertView 的按钮被点击之前播放音频,那么设置 audioPlayer.numberOfLoops = -1;

【讨论】:

  • 你怎么知道它不是安卓? 儿童应用是不是给您带来了启发?
  • 答案仅适用于 ios...
猜你喜欢
  • 1970-01-01
  • 2018-02-05
  • 2013-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
相关资源
最近更新 更多