喜, 我有文本框和一个图像视图。 我有两个名为CAT和DOG的图像。 当我在文本框中输入文本时,图像视图将显示相应的命名图像。 如果我输入的字不是DOG和CAT(意思是:我的应用程序中没有与文本框中的值名称相同的图像),或者没有找到网址,我需要发出嘟嘟声。 任何人都可以告诉我一个很好的方法来做到这一点。 现在我只是显示一个名为“无图像”的图像。在这种情况下,我需要发出哔哔声。
0
A
回答
1
3
我们可以用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];
+0
+1对于TNG_Theme :) – Joshua 2013-08-18 15:06:19
相关问题
- 1. 为什么我的控制台应用程序发出哔声?
- 2. 在Linux中发出哔哔声C
- 3. Python程序运行时发出哔声?
- 4. 如何防止MaxLength发出哔哔声或者完全防止应用程序发出蜂鸣声?
- 5. 在Maven构建过程中发出计算机哔哔声
- 6. ALT +快捷键会发出“哔哔”声
- 7. 在android应用程序中执行哔声声音
- 8. 使用sl4a发出手机哔声
- 9. 如何用PyFace发出哔声?
- 10. c#避免在KeyDown按下发出哔哔声?
- 11. Java Swing - 如何在任何JOptionPane之前发出哔哔声?
- 12. 下面的代码如何使PC发出哔哔声?
- 13. FF中的音频控制发出哔哔声,OGG和.htaccess已被修改
- 14. IE输入哔哔声
- 15. 如何在输入按下时防止文本框发出哔哔声?
- 16. Xamarin使用哔声()
- 17. 当按键被击中时发出不必要的哔声
- 18. 内置扬声器在Windows 8嵌入式标准中发出哔声
- 19. 如何在Click Mouse中禁用哔声?
- 20. 的声音在我的应用程序
- 21. 为什么下面的代码会让我的电脑发出哔声?
- 22. 哔声流激活
- 23. 如何在显示二进制数据时阻止我的Windows控制台应用程序触发器发出哔声
- 24. 使用MediaPlayer播放谷歌电视上的通知哔哔声
- 25. android在我的应用程序中发出错误呼叫
- 26. Socket连接建立时发出哔声通知
- 27. 如何使C#计算机发出哔声?
- 28. 无限制系统扬声器哔哔声
- 29. 我应该使用哪种IDE在IronPython中开发单声道应用程序?
- 30. 在背景中播放哔声
这不是Xcode的,但可可触摸相关。请使用适当的标签。 – vikingosegundo 2011-07-03 21:17:34