开始录音时的警报声音



我第一次在我的应用程序中捕捉视频,但是当我开始捕捉时,我想要那个按钮点击声音作为本地应用程序。我搜索了很多,知道这是一个系统的声音。有没有人能告诉我,当我开始捕捉视频和停止捕捉时,我如何在我的应用程序中添加声音。

目前我正在使用AVAudioPlayer播放声音,如下所示

  NSURL *url1 = [[NSBundle mainBundle] URLForResource:str withExtension:@"wav"];
_startAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:nil];
_startAudioPlayer.delegate= self;
[_startAudioPlayer prepareToPlay];
[_startAudioPlayer play];

Thanks in advance.....

直接导入AudioToolbox.framework
为源音频文件

创建URL
NSURL *tapSound   = [[NSBundle mainBundle] URLForResource: @"tap"
                                                withExtension: @"aif"];

// Store the URL as a CFURLRef instance
self.soundFileURLRef = (CFURLRef) [tapSound retain];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
    soundFileURLRef,
    &soundFileObject
);

播放声音

AudioServicesPlayAlertSound (soundFileObject);

这是一个很好的教程链接,你可以点击

当你想在那个时候开始捕捉视频时,像这样调用这个bellow方法…

[self playSound];

使用my this bellow方法播放声音

-(void)playSound
{ 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"adriantnt_release_click" ofType:@"mp3"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate=self;
    [theAudio play];
}

首先在您的项目文件夹中存储任何mp3或任何音频文件,例如:我添加adriantnt_release_click.mp3文件。

还添加AVAudioPlayerDelegate在您的.h文件和添加AudioToolbox.framework在您的项目..

最新更新