In this fourth part of the JNI tutorial series, we use the Java native interface to maintain an external resource with a state. Specifically, our example opens and plays an Opus audio file through the opusfile API, but the pattern is general enough to be used for any kind of resource. Getting a handle As… Continue reading A simple Opus audio player with JNI
Category: JNI Tutorial
Moving native data in byte buffers
This third part in the JNI tutorial series focuses on processing chunks of data, either moving them between native code and Java, or just keeping tabs on them in Java while keeping the actual data outside the JVM. We’ve seen how values can be passed to and from native methods as parameters and return values,… Continue reading Moving native data in byte buffers
Error handling in JNI
In this second part of the JNI tutorial series, we attack error handling, to get that annoying subject out of the way as soon and as much as possible. There’s no complete example for this part in the tutorial example zip file (because you can’t write a program that only does error handling), but you… Continue reading Error handling in JNI
Tutorial: The Java native interface to C code
This post is the first in a tutorial series about how JNI, the Java native interface, can be used to call C code from a Java program. We start with the basics and finish with a useful Java class that uses an external library for its core operation. Along the way, we look at some… Continue reading Tutorial: The Java native interface to C code