Solved it. Strange as it is, but the solution that worked for me involved 2 steps (apart from what I wrote above):
create an AVAudioEngine and setup voice processing on its input node.
When the AVPlayer loads, override the output port.
Code:
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.playAndRecord,
mode: .videoChat,
options: [.defaultToSpeaker,
.allowAirPlay,
.allowBluetooth])
try audioSession.setActive(true)
let engine = AVAudioEngine()
try engine.inputNode.setVoiceProcessingEnabled(true)
let playerItem = AVPlayerItem(url: ...)
let player = AVPlayer(playerItem: playerItem)
var observer: NSKeyValueObservation? = nil
observer = playerItem.observe(\.status, options: [.new, .old], changeHandler: { (playerItem, change) in
if playerItem.status == .readyToPlay {
try? audioSession.overrideOutputAudioPort(.speaker)
}
}
player.play()
Topic:
Media Technologies
SubTopic:
Audio
Tags: