No sound when playing audio over car system with Bluetooth

Hi

I am developing an app which plays spoken audio. I experience problems when I want to play audio over the car system with Bluetooth. The Bluetooth connection is fine and other audio apps (e.g. Spotify) just work fine. When I want to play audio with my app, I can start audio playback successfully but I hear no sound. It works with the device speakers and interestingly even with another mobile Bluetooth sound box. Both the car system and the mobile soundbox use A2DP.

Below you can find the relevant method that starts the audio playback. The full app can be found at https://gitlab.com/spiri-voyage/spiri-test.

  

func play() {

       
if playbackState == .Stopped {

           
let url = Bundle.main.path(forResource: "Kolinbrunnen", ofType:
"mp3")

           
let item = AVPlayerItem(url: URL(fileURLWithPath: url!))

           
player.replaceCurrentItem(with: item)

           
let audioSession = AVAudioSession.sharedInstance()

           

do
{

               
try audioSession.setCategory(.playback, mode: .spokenAudio)

               
addInfo("Audio session category configured for foreground.")

               
try audioSession.setActive(true)

               
addInfo("Audio session activated.")

               
player.play()

               
addInfo("Playing audio.")

               
playbackState = .Playing

           
}

           
catch {

               
addInfo("Failed to play audio: error setting category or activating audio
session.")

           
}

       
}

       
else if playbackState == .Paused {

           
player.play()

           
addInfo("Audio resumed.")

           
playbackState = .Playing

       
}

       
else {

           
addInfo("Ignoring play command: audio already playing.")

       
}

   
}

Is the audio session handling wrong? Do I not use the AVPlayer correctly? I read the documentation many times, I don't know what else to do.

Tested with iPhone SE, software version 14.4.2.

Any help is greatly appreciated.

Kind regards Rony

No sound when playing audio over car system with Bluetooth
 
 
Q