Skip to content

Commit 99e6fcc

Browse files
stanis-kgithub-actions[bot]
authored andcommitted
Stop TTS on the background thread only to avoid ANRs (#10905)
* Stop TTS on the background thread only to avoid ANRs * Add changelog * Fix test * Fix ktlint GitOrigin-RevId: 27bdfef6368ff657d4a702fe3c25bf6c7e2d7608
1 parent 27f5074 commit 99e6fcc

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix ANR when calling `MapboxVoiceInstructionsPlayer::stop`

voice/src/main/java/com/mapbox/navigation/voice/api/VoiceInstructionsTextPlayer.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ internal class VoiceInstructionsTextPlayer(
101101
* Clears any announcements queued.
102102
*/
103103
override fun clear() {
104-
getTextToSpeechOrNull()?.stop()
104+
jobControl.scope.launch {
105+
val tts = getTextToSpeechOrNull() ?: return@launch
106+
if (tts.isSpeaking) {
107+
tts.stop()
108+
}
109+
}
105110
currentPlay = null
106111
}
107112

voice/src/test/java/com/mapbox/navigation/voice/api/VoiceInstructionsTextPlayerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class VoiceInstructionsTextPlayerTest {
249249
@Test
250250
fun `text to speech stop is called is called when clear`() = runTest {
251251
val textPlayer = initTextPlayer()
252+
every { mockedTextToSpeech.isSpeaking } returns true
252253

253254
textPlayer.clear()
254255

0 commit comments

Comments
 (0)