在我的应用程序中发出**嘟嘟声**?

发布于 2024-11-11 08:15:50 字数 384 浏览 0 评论 0原文

可能的重复:
如何让 Iphone 发出蜂鸣声

嗨, 我有文本框和图像视图。 我有两张图像,分别命名为 CAT 和 DOG。 当我在文本框中输入文本时,图像视图将显示当前的命名图像。 如果我输入的单词不是 DOG 和 CAT(意味着:我的应用程序中没有与文本框值名称相同的图像)或者没有找到 url,我需要发出蜂鸣声。 谁能告诉我一种好方法。 现在我只是显示一个名为“无图像”的图像。在这种情况下我需要发出嘟嘟声。

Possible Duplicate:
How do you make an Iphone beep

hi,
i have text box and a image view.
i have two images named as CAT and DOG.
when i entered texts in my text box ,image view will display the curresponding named images.
if i entered a word that is not DOG and CAT(means: there is no image in my app same as text box value name) or there is no url found i need to make a beep sound.
can any one tell me a good way to do it.
now i am simply showing an image named as "no image". i need to make a beep sound at this situation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情别恋 2024-11-18 08:15:50

我们可以使用 AVAudioPlayer

#import <UIKit/UIKit.h>
@class AVAudioPlayer;

@interface AudioPlayer : UIViewController {
  AVAudioPlayer *audioPlayer;
}

@property (nonatomic, retain) AVAudioPlayer *audioPlayer;

-(IBAction)play;
-(IBAction)stop;

@end

@implementation AudioPlayer

- (void)viewDidLoad {
  [super viewDidLoad];

  // Get the file path to the song to play.
  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TNG_Theme"
                                                       ofType:@"mp3"];

  // Convert the file path to a URL.
  NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

  //Initialize the AVAudioPlayer.
  self.audioPlayer = [[AVAudioPlayer alloc]
                           initWithContentsOfURL:fileURL error:nil];

  // Preloads the buffer and prepares the audio for playing.
  [self.audioPlayer prepareToPlay];

  [filePath release];
  [fileURL release];
}

播放

  // Make sure the audio is at the start of the stream.
  self.audioPlayer.currentTime = 0;
  [self.audioPlayer play];

停止

  [self.audioPlayer stop];

We can use AVAudioPlayer:

#import <UIKit/UIKit.h>
@class AVAudioPlayer;

@interface AudioPlayer : UIViewController {
  AVAudioPlayer *audioPlayer;
}

@property (nonatomic, retain) AVAudioPlayer *audioPlayer;

-(IBAction)play;
-(IBAction)stop;

@end

@implementation AudioPlayer

- (void)viewDidLoad {
  [super viewDidLoad];

  // Get the file path to the song to play.
  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TNG_Theme"
                                                       ofType:@"mp3"];

  // Convert the file path to a URL.
  NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

  //Initialize the AVAudioPlayer.
  self.audioPlayer = [[AVAudioPlayer alloc]
                           initWithContentsOfURL:fileURL error:nil];

  // Preloads the buffer and prepares the audio for playing.
  [self.audioPlayer prepareToPlay];

  [filePath release];
  [fileURL release];
}

To play

  // Make sure the audio is at the start of the stream.
  self.audioPlayer.currentTime = 0;
  [self.audioPlayer play];

To stop

  [self.audioPlayer stop];
碍人泪离人颜 2024-11-18 08:15:50

请参阅此主题

如何让 iPhone 发出蜂鸣声?

这是

Iphone内置蜂鸣音效

您可能还想观看此视频

http://www.youtube.com/watch?v=iUDnUAveqtU

See this thread

How do you make an iPhone beep?

Another thread on this is

has Iphone built in beep sound effect

You may also wanted to see this video

http://www.youtube.com/watch?v=iUDnUAveqtU

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文