I am attempting to play a sound clip using AVAudioPlayer while having an active PeerConnection using the GoogleWebRTC Obj-C library for iOS.
When I play the sound, I can hear it through the speakers, but it plays at an extremely low (almost inaudible) volume in comparison with the WebRTC Audio output.
I have AVAudioSession set to active = true with the following; AVAudioSession.Category = .playAndRecord, AVAudioSession.CategoryOptions = [.defaultToSpeaker, .allowBluetooth, .mixWithOthers], AVAudioSession.Mode = .voiceChat.
I have no trouble playing and hearing sounds when there is not an actively configured WebRTC audio connection.
Is there a way to allow sound to play from an AVAudioPlayer without it being lowered in volume via WebRTC?
do {
try setActiveAudio()
let player = try AVAudioPlayer(data: asset.data, fileTypeHint: AVFileType.mp3.rawValue)
activePlayers.append(player)
player.delegate = self
player.prepareToPlay()
player.play()
} catch let error {
print(error.localizedDescription)
}
Thank you for any help.
Before play audio, change mode to default, also will lost aec, agc support,
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeDefault error:&error];
when finish play, reset mode to voice chat,
[[AVAudioSession sharedInstance] AVAudioSessionModeVoiceChat error:&error];
I have faced somewhat similar issue, when the ringer is off. Can you
Make sure the current output port is speaker.
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];