Avplayer issue playing video audio from speakers in ios 14.2.1

Hi guys,

We implement Avplayer in our app - but it seems to have this odd problem where the audio does not play from the speakers on ios 14.2.1 Seems to work fine on 14.2

Is there some setting or configuration that we can use to get around this?

Many thanks

I'm having this problem on 14.6 even.

This is my audioSession setup:

        try audioSession.setCategory(.playAndRecord,
              mode: .videoChat,
              options: [.duckOthers,
                    .defaultToSpeaker,
                    .allowAirPlay,
                    .allowBluetooth])

Solved it. Strange as it is, but the solution that worked for me involved 2 steps (apart from what I wrote above):

  1. create an AVAudioEngine and setup voice processing on its input node.
  2. 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()
Avplayer issue playing video audio from speakers in ios 14.2.1
 
 
Q