Timer Pauses When Playing Apple Music, AvAudioPlayer and Synthesizer

In my workout app, I play workout music locally using AvAudioPlayer. There's a one-second timer firing to update a countdown clock and progress circle. I also play text through the Synthesizer and sound effects through AvAudioPlayer. It all works smoothly. There's no hesitation at any time in the UI to update the countdown clock or progress circle.

I added the ability to play music through Apple Music. Not everything works smoothly. Switching the audio session to duckothers mode to turn down the volume on Apple Music while the synth plays causes problems. You can't switch sessions while something is playing in AvAudioPlayer, which happens while I'm playing sound effects. It's a timing mess, but solvable.

What I can't figure out is that in the periods when Apple Music is playing, the AvAudioPlayer is playing, and the synth is speaking, the UI visibly freezes for a second or so and then resumes. If I don't play sound effects through AvAudioPlayer, the UI does not freeze.

I tried various "DispatchQueue.global(qos: options", but I think it all just goes into the OS subsystem anyway, so it's not really running in the calling thread context.

So, after this torturous setup, is there a way to condition priorities, threads, or some other mechanism in swiftui to make sure the timer gets enough priority to operate smoothly at all times?

thanks

Timer Pauses When Playing Apple Music, AvAudioPlayer and Synthesizer
 
 
Q