Skip to content

Commit e5fd924

Browse files
committed
NAVAND-1001: use immediate dispatcher to guarantee that language will change before voice instructions
1 parent f3043af commit e5fd924

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ This release depends on, and has been tested with, the following Mapbox dependen
6363
- Mapbox Core Common `v23.2.1`
6464
- Mapbox Java `v6.10.0-beta.3` ([release notes](https://github.com/mapbox/mapbox-java/releases/tag/v6.10.0-beta.3))
6565

66+
- Fixed an issue where the first voice instruction might have been played twice. [#6766](https://github.com/mapbox/mapbox-navigation-android/pull/6766)
6667

6768
## Mapbox Navigation SDK 2.9.5 - 13 December, 2022
6869
### Changelog

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlinx.coroutines.CoroutineDispatcher
1414
import kotlinx.coroutines.CoroutineScope
1515
import kotlinx.coroutines.Dispatchers
1616
import kotlinx.coroutines.ExperimentalCoroutinesApi
17-
import kotlinx.coroutines.FlowPreview
1817
import kotlinx.coroutines.Job
1918
import kotlinx.coroutines.SupervisorJob
2019
import kotlinx.coroutines.flow.Flow
@@ -25,9 +24,7 @@ import kotlinx.coroutines.flow.combine
2524
import kotlinx.coroutines.flow.distinctUntilChanged
2625
import kotlinx.coroutines.flow.filter
2726
import kotlinx.coroutines.flow.first
28-
import kotlinx.coroutines.flow.flatMapConcat
2927
import kotlinx.coroutines.flow.flatMapLatest
30-
import kotlinx.coroutines.flow.flowOf
3128
import kotlinx.coroutines.flow.map
3229
import kotlinx.coroutines.flow.updateAndGet
3330
import kotlinx.coroutines.launch
@@ -123,7 +120,7 @@ internal constructor(
123120
/**
124121
* Top level flow that will switch based on the language and muted state.
125122
*/
126-
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
123+
@OptIn(ExperimentalCoroutinesApi::class)
127124
private fun audioGuidanceFlow(
128125
mapboxNavigation: MapboxNavigation
129126
): Flow<MapboxAudioGuidanceState> {
@@ -146,18 +143,15 @@ internal constructor(
146143
} else {
147144
voiceInstructions
148145
.filter { it.voiceInstructions != lastPlayedInstructions }
149-
.flatMapConcat {
146+
.map {
150147
lastPlayedInstructions = it.voiceInstructions
151148
val announcement = audioGuidance.speak(it.voiceInstructions)
152-
flowOf(announcement)
153-
}
154-
.map { speechAnnouncement ->
155-
internalStateFlow.updateAndGet {
149+
internalStateFlow.updateAndGet { state ->
156150
MapboxAudioGuidanceState(
157-
isPlayable = it.isPlayable,
158-
isMuted = it.isMuted,
159-
voiceInstructions = it.voiceInstructions,
160-
speechAnnouncement = speechAnnouncement
151+
isPlayable = state.isPlayable,
152+
isMuted = state.isMuted,
153+
voiceInstructions = state.voiceInstructions,
154+
speechAnnouncement = announcement
161155
)
162156
}
163157
}
@@ -195,7 +189,10 @@ internal constructor(
195189
* Construct an instance without registering to [MapboxNavigationApp].
196190
*/
197191
@JvmStatic
198-
fun create() = MapboxAudioGuidance(MapboxAudioGuidanceServices(), Dispatchers.Main)
192+
fun create() = MapboxAudioGuidance(
193+
MapboxAudioGuidanceServices(),
194+
Dispatchers.Main.immediate
195+
)
199196

200197
/**
201198
* Get the registered instance or create one and register it to [MapboxNavigationApp].

0 commit comments

Comments
 (0)