Post

Replies

Boosts

Views

Activity

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
0
0
410
Aug ’23
Change the Volume for ApplicationMusicPlayer to hear the voice synthesizer?
My app uses the voice synthesizer, and I'm trying to integrate apple music into my app using MusicKit to play a playlist during a workout. I want to lower the volume of the music while the synthesizer is speaking so the user can hear it. When I play music locally using AVAudioPlayer this is possible. I'm using the ApplicationMusicPlayer to play the tracks of the playlist. I don't see a way to lower the volume ApplicationMusicPlayer programmatically. Is there a way to programmatically change the volume of the ApplicationMusicPlayer? Or is there a better way to accomplish what I'm trying to do? thanks
1
0
466
Aug ’23