@@ -14,7 +14,6 @@ import kotlinx.coroutines.CoroutineDispatcher
1414import kotlinx.coroutines.CoroutineScope
1515import kotlinx.coroutines.Dispatchers
1616import kotlinx.coroutines.ExperimentalCoroutinesApi
17- import kotlinx.coroutines.FlowPreview
1817import kotlinx.coroutines.Job
1918import kotlinx.coroutines.SupervisorJob
2019import kotlinx.coroutines.flow.Flow
@@ -25,9 +24,7 @@ import kotlinx.coroutines.flow.combine
2524import kotlinx.coroutines.flow.distinctUntilChanged
2625import kotlinx.coroutines.flow.filter
2726import kotlinx.coroutines.flow.first
28- import kotlinx.coroutines.flow.flatMapConcat
2927import kotlinx.coroutines.flow.flatMapLatest
30- import kotlinx.coroutines.flow.flowOf
3128import kotlinx.coroutines.flow.map
3229import kotlinx.coroutines.flow.updateAndGet
3330import 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,7 @@ internal constructor(
195189 * Construct an instance without registering to [MapboxNavigationApp].
196190 */
197191 @JvmStatic
198- fun create () = MapboxAudioGuidance (MapboxAudioGuidanceServices (), Dispatchers .Main )
192+ fun create () = MapboxAudioGuidance (MapboxAudioGuidanceServices (), Dispatchers .Main .immediate )
199193
200194 /* *
201195 * Get the registered instance or create one and register it to [MapboxNavigationApp].
0 commit comments