ios - 应用加入 agora.io channel 时 AVAudioPlayer 自动停止

标签 ios objective-c avaudioplayer avaudiosession agora.io

当用户在我的应用程序中点击调用按钮/加入 channel (Agora)时,我添加了声音。

    [self.agoraKit joinChannelByToken:self.userManager.agoraToken channelId:self.userManager.channelName info:nil uid:[self.userManager.UID integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"ringing-sound-jalebi" ofType:@"mp3"];
        NSURL *soundFileURL = [NSURL fileURLWithPath:path];
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
        self.audioPlayer.delegate = self;
       [self.audioPlayer play];
     }];

但我收到“AVAudioSession.mm:997:-[AVAudioSession setActive:withOptions:error:]: 停用正在运行 I/O 的 Audio Session 。在停用音频之前应停止或暂停所有 I/O session ”错误。有人可以帮我解决这个问题

最佳答案

当您加入通话时,Agora SDK 似乎会自动停用任何现有的 AVAudioSession,以确保您可以听到与您通话的人的声音。我建议通过 Agora 的 sound mixing API 播放声音。相反。

// Plays an audio effect file.
int soundId = 1; // The sound ID of the audio effect file to be played.
NSString *path = [[NSBundle mainBundle] pathForResource:@"ringing-sound-jalebi" ofType:@"mp3"]; // The file path of the audio effect file.
int loopCount = 1; // The number of playback loops. -1 means an infinite loop.
double pitch = 1; // Sets the pitch of the audio effect.
double pan = 1; // Sets the spatial position of the audio effect. 0 means the effect shows ahead.
double gain = 100; // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
BOOL publish = true; // Sets whether to publish the audio effect.
[self.agoraKit playEffect:soundId filePath:path loopCount:loopCount pitch:pitch pan:pan gain:gain publish:publish];

关于ios - 应用加入 agora.io channel 时 AVAudioPlayer 自动停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61076371/

相关文章:

OBJ-C 中的 C++ 图形等价物

ios - drawViewHierarchyInRect :afterScreenUpdates: delays other animations

ios - 为什么 Google map 崩溃并出现 "Attempt to set an unknown enum value"错误?

ios - 如何永久修复 Xcode 5 SpringBoard 无法启动应用程序,错误为 : -3

ios - TCP 套接字在运行 iOS 10.3.2 的 iPhone 7 上不起作用

iphone - iOS:什么是音频单元?

ios - 按下点击手势识别器时 AVAudioPlayer 不播放声音

iphone - 使用AVAudioPlayer播放的音频在iPhone模拟器中有效,但在设备中不起作用

iphone - 某些 UITextfields 在 iOs6 中没有响应

ios - 我如何从 coreData swift 获取用户最近的聊天记录