ios - 同时播放2个音频objective-c
问题描述
我有一个 AVPlayer 与摄像机的实时流一起运行,当用户触摸按钮拍摄快照时,我想播放另一个音频(摄像机快照音频效果)
所以我添加了这段代码
- (void)screenFlash {
NSString *soundFilePath = [NSString stringWithFormat:@"%@/Snapshoot.m4a",[[NSBundle mainBundle] resourcePath]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1;
[player play];
UIView *flash = [[UIView alloc] initWithFrame:self.view.frame];
flash.backgroundColor = UIColor.whiteColor;
flash.alpha=1;
[self.view addSubview:flash];
[UIView animateWithDuration:0.3 animations:^{
flash.alpha=0;
} completion:^(BOOL finished) {
[flash removeFromSuperview];
}];
}
如果我在 [播放器播放] 之前放置一个断点,音频听起来很完美,但如果我禁用断点,音频就不会重现。
有人知道为什么吗?我可以同时播放两个音频(相机音频和快照效果)吗?
解决方案
您可以使用这样的东西来播放相机快照音频效果。非常适合我。
#import <AudioToolbox/AudioToolbox.h>
......................................
AudioServicesPlaySystemSound(1108);
推荐阅读
- python-3.x - Python SQLite 更新函数在使用中出错。它一直说'='符号旁边有一个错误
- mapping - 如何迭代 string_table 和修改行
- c# - 如何从 Oxplot 图中删除轴但保留缩放和平移功能?
- java - Android Studio 3.5.3 更新后在新项目的 XML 文件中创建奇怪的字符
- jenkins - 如何在詹金斯的aws帐户之间切换?
- java - log4j 将“sg”添加到每个记录的行
- c++ - 什么值存储在对齐的结构/类对象的填充字节中
- tws - 在哪里定义了哪个回调用于 EClient 中的特定方法
- batch-file - 从选择的文件夹中创建子驱动器
- batch-file - 创建多个 *.bat 文件