mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-17 12:39:36 +00:00
Store the TTS object in the struct.
This commit is contained in:
parent
da8260cba8
commit
84926ea110
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user