Skip to content

Commit

Permalink
ndk-examples: update to use jni 0.20 (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
rib authored Nov 21, 2022
1 parent 4c01bd2 commit fefc1cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ndk-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
publish = false

[target.'cfg(target_os = "android")'.dependencies]
jni = "0.19"
jni = "0.20"
libc = "0.2"
log = "0.4.14"
ndk = { path = "../ndk", features = ["api-level-23"] }
Expand Down
9 changes: 6 additions & 3 deletions ndk-examples/examples/jni_audio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use jni::objects::JObject;

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
fn main() {
enumerate_audio_devices().unwrap();
Expand All @@ -9,6 +11,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {
// Create a VM for executing Java calls
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let context = unsafe { JObject::from_raw(ctx.context().cast()) };
let env = vm.attach_current_thread()?;

// Query the global Audio Service
Expand All @@ -17,7 +20,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {

let audio_manager = env
.call_method(
ctx.context().cast(),
context,
"getSystemService",
// JNI type signature needs to be derived from the Java API
// (ArgTys)ResultTy
Expand All @@ -36,7 +39,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {

println!("-- Output Audio Devices --");

let device_array = devices.l()?.into_inner();
let device_array = devices.l()?.into_raw();
let len = env.get_array_length(device_array)?;
for i in 0..len {
let device = env.get_object_array_element(device_array, i)?;
Expand All @@ -56,7 +59,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {
let sample_array = env
.call_method(device, "getSampleRates", "()[I", &[])?
.l()?
.into_inner();
.into_raw();
let len = env.get_array_length(sample_array)?;

let mut sample_rates = vec![0; len as usize];
Expand Down

0 comments on commit fefc1cb

Please sign in to comment.