Skip to content

Commit b7a5147

Browse files
committed
add docs to say that MapboxVoiceInstructionsPlayer should be initialized in onCreate
1 parent bdbca31 commit b7a5147

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

examples/src/main/java/com/mapbox/navigation/examples/core/MapboxVoiceActivity.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,13 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
103103
/**
104104
* The [MapboxVoiceInstructionsPlayer] consumes the voice instructions data
105105
* and plays them using the appropriate TTS player.
106+
* NOTE: do not use lazy initialization for this class since it takes some time to initialize
107+
* the system services required for on-device speech synthesis. With lazy initialization
108+
* there is a high risk that said services will not be available when the first instruction
109+
* has to be played. [MapboxVoiceInstructionsPlayer] should be instantiated in
110+
* `Activity#onCreate`.
106111
*/
107-
private val voiceInstructionsPlayer: MapboxVoiceInstructionsPlayer by lazy {
108-
val options = VoiceInstructionsPlayerOptions.Builder()
109-
.abandonFocusDelay(PLAYER_ABANDON_FOCUS_DELAY)
110-
.build()
111-
MapboxVoiceInstructionsPlayer(
112-
this,
113-
Locale.US.toLanguageTag(),
114-
options
115-
)
116-
}
112+
private lateinit var voiceInstructionsPlayer: MapboxVoiceInstructionsPlayer
117113

118114
private val routeLineResources: RouteLineResources by lazy {
119115
RouteLineResources.Builder().build()
@@ -378,6 +374,13 @@ class MapboxVoiceActivity : AppCompatActivity(), OnMapLongClickListener {
378374
setLocationProvider(navigationLocationProvider)
379375
enabled = true
380376
}
377+
voiceInstructionsPlayer = MapboxVoiceInstructionsPlayer(
378+
this,
379+
Locale.US.toLanguageTag(),
380+
VoiceInstructionsPlayerOptions.Builder()
381+
.abandonFocusDelay(PLAYER_ABANDON_FOCUS_DELAY)
382+
.build()
383+
)
381384
init()
382385
}
383386

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import kotlin.concurrent.schedule
1818
/**
1919
* Hybrid implementation of [MapboxVoiceInstructionsPlayer] combining [VoiceInstructionsTextPlayer] and
2020
* [VoiceInstructionsFilePlayer] speech players.
21+
* NOTE: do not use lazy initialization for this class since it takes some time to initialize
22+
* the system services required for on-device speech synthesis. With lazy initialization
23+
* there is a high risk that said services will not be available when the first instruction
24+
* has to be played. [MapboxVoiceInstructionsPlayer] should be instantiated in
25+
* `Activity#onCreate`.
26+
*
2127
* @param context Context
2228
* @param language [Locale] language (in a format acceptable by [Locale])
2329
* @param options [VoiceInstructionsPlayerOptions] (optional)

0 commit comments

Comments
 (0)