繁体   English   中英

开始录制时发出警报声

[英]alert sound when start recording

第一次在应用程序中捕获视频,但是当我开始捕获时,我希望该按钮单击声音作为本机应用程序。 我进行了很多搜索,才知道这是系统声音。 谁能告诉我在开始捕获视频时和停止捕获时如何在应用程序中添加声音。

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

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

提前致谢.....

只需导入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);

这是一个不错的教程链接,您可以关注

当您想在那时开始捕获视频时,请像下面这样调用以下波纹管方法...

[self playSound];

使用我的这种波纹管方法播放声音...

-(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文件。

还要在.h文件中添加AVAudioPlayerDelegate ,并在项目中添加AudioToolbox.framework

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM