@@ -14,7 +14,6 @@ import kotlinx.coroutines.CoroutineDispatcher
14
14
import kotlinx.coroutines.CoroutineScope
15
15
import kotlinx.coroutines.Dispatchers
16
16
import kotlinx.coroutines.ExperimentalCoroutinesApi
17
- import kotlinx.coroutines.FlowPreview
18
17
import kotlinx.coroutines.Job
19
18
import kotlinx.coroutines.SupervisorJob
20
19
import kotlinx.coroutines.flow.Flow
@@ -25,9 +24,7 @@ import kotlinx.coroutines.flow.combine
25
24
import kotlinx.coroutines.flow.distinctUntilChanged
26
25
import kotlinx.coroutines.flow.filter
27
26
import kotlinx.coroutines.flow.first
28
- import kotlinx.coroutines.flow.flatMapConcat
29
27
import kotlinx.coroutines.flow.flatMapLatest
30
- import kotlinx.coroutines.flow.flowOf
31
28
import kotlinx.coroutines.flow.map
32
29
import kotlinx.coroutines.flow.updateAndGet
33
30
import kotlinx.coroutines.launch
@@ -123,7 +120,7 @@ internal constructor(
123
120
/* *
124
121
* Top level flow that will switch based on the language and muted state.
125
122
*/
126
- @OptIn(ExperimentalCoroutinesApi ::class , FlowPreview :: class )
123
+ @OptIn(ExperimentalCoroutinesApi ::class )
127
124
private fun audioGuidanceFlow (
128
125
mapboxNavigation : MapboxNavigation
129
126
): Flow <MapboxAudioGuidanceState > {
@@ -146,18 +143,15 @@ internal constructor(
146
143
} else {
147
144
voiceInstructions
148
145
.filter { it.voiceInstructions != lastPlayedInstructions }
149
- .flatMapConcat {
146
+ .map {
150
147
lastPlayedInstructions = it.voiceInstructions
151
148
val announcement = audioGuidance.speak(it.voiceInstructions)
152
- flowOf(announcement)
153
- }
154
- .map { speechAnnouncement ->
155
- internalStateFlow.updateAndGet {
149
+ internalStateFlow.updateAndGet { state ->
156
150
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
161
155
)
162
156
}
163
157
}
@@ -195,7 +189,10 @@ internal constructor(
195
189
* Construct an instance without registering to [MapboxNavigationApp].
196
190
*/
197
191
@JvmStatic
198
- fun create () = MapboxAudioGuidance (MapboxAudioGuidanceServices (), Dispatchers .Main )
192
+ fun create () = MapboxAudioGuidance (
193
+ MapboxAudioGuidanceServices (),
194
+ Dispatchers .Main .immediate
195
+ )
199
196
200
197
/* *
201
198
* Get the registered instance or create one and register it to [MapboxNavigationApp].
0 commit comments