davidsansome / tsurukame

Tsurukame is an unofficial WaniKani app for iOS. It helps you learn Japanese Kanji.
https://tsurukame.app
Apache License 2.0
264 stars 63 forks source link

Deactivate audio session off main thread #754

Closed jamescarlson closed 2 months ago

jamescarlson commented 2 months ago

I noticed an issue of momentary UI/interactivity stutters happening at the end of vocabulary audio playback. The stuttering would cause dropped keystrokes on the on-screen keyboard, or incorrect words to be input when using the swipe keyboard.

To reproduce the stutter, have another app on the device currently using an audio session, and then do some reviews and make sure to try typing around the time the audio playback finishes. I noticed the stutter when on a voice call concurrently while doing reviews, but it may also happen with other audio session types.

I tracked this issue down to the setActive(false, ...) of the audio session which happens on the main thread, and I imagine it has to do with the .notifyOthersOnDeactivation option letting another app block the main thread.

Either way, I tried changing the audio session setActive to happen outside of the main thread, and with that change, I was no longer able to reproduce the stutter behavior on my local device.

davidsansome commented 2 months ago

Wow great find, thank you!