作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
什么代码可以让我在iPhone上产生标准的提示音?
最佳答案
好吧,这取决于您想要哪种声音。
这是使用AVFoundation音频框架播放声音的方法。
#import <UIKit/UIKit.h>
@class AVAudioPlayer;
@interface AudioPlayer : UIViewController {
IBOutlet UIButton *playButton;
IBOutlet UIButton *stopButton;
AVAudioPlayer *audioPlayer;
}
@property (nonatomic, retain) IBOutlet UIButton *playButton;
@property (nonatomic, retain) IBOutlet UIButton *stopButton;
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
-(IBAction)play;
-(IBAction)stop;
@end
- (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];
}
-(IBAction)play {
// Make sure the audio is at the start of the stream.
self.audioPlayer.currentTime = 0;
[self.audioPlayer play];
}
-(IBAction)stop {
[self.audioPlayer stop];
}
关于iphone - 您如何使iPhone发出哔哔声?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508704/
我是一名优秀的程序员,十分优秀!