@@ -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
0 commit comments