From 84926ea1105bdde5d4083cbec1d55e2b98eac112 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 29 Dec 2020 15:47:11 -0600 Subject: [PATCH] Store the TTS object in the struct. --- src/backends/android.rs | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/backends/android.rs b/src/backends/android.rs index 6b4e66a..2b28d20 100644 --- a/src/backends/android.rs +++ b/src/backends/android.rs @@ -27,27 +27,19 @@ impl Android { let id = BackendId::Android(*backend_id); *backend_id += 1; let native_activity = ndk_glue::native_activity(); - let mut vm = VM.lock().unwrap(); - if vm.is_none() { - let vm_ptr = native_activity.vm(); - let new_vm = unsafe { jni::JavaVM::from_raw(vm_ptr) }?; - *vm = Some(new_vm); - } - if let Some(vm) = &*vm { - let env = vm.attach_current_thread()?; - let tts = env.new_object( - "android/speech/tts/TextToSpeech", - "(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V", - &[ - native_activity.activity().into(), - native_activity.activity().into(), - ], - )?; - let tts = env.new_global_ref(tts)?; - Ok(Self { id, tts }) - } else { - Err(Error::NoneError) - } + let vm_ptr = native_activity.vm(); + let vm = unsafe { jni::JavaVM::from_raw(vm_ptr) }?; + let env = vm.attach_current_thread()?; + let tts = env.new_object( + "android/speech/tts/TextToSpeech", + "(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V", + &[ + native_activity.activity().into(), + native_activity.activity().into(), + ], + )?; + let tts = env.new_global_ref(tts)?; + Ok(Self { id, tts }) } }