同时播放 2 个音频 objective-c

Play 2 audios at same time 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];
}];
}

如果我在 [player play] 之前放置一个断点,音频听起来很完美,但如果我禁用断点,音频就不会再现。

有人知道为什么吗?我可以同时播放两个音频(相机音频和快照效果)吗?

你可以使用类似这样的东西来播放相机快照音效。 非常适合我。

 #import <AudioToolbox/AudioToolbox.h>
 ......................................
 AudioServicesPlaySystemSound(1108);