Skip to main content
Kotlin/JVM bindings with no JNI and no native glue to compile: they use the Java Foreign Function & Memory API (JEP 454, stable since JDK 22) to locate librockbox_ffi at runtime and bind every function to a MethodHandle downcall.
Requires a JDK 22+. The published jar bundles a prebuilt librockbox_ffi for every OS/arch — it extracts the matching one at load time, so consumers need no Rust toolchain. ROCKBOX_FFI_LIB overrides; a repo checkout falls back to target/release.
FFM’s restricted native calls need --enable-native-access=ALL-UNNAMED on the launch command (the project’s Gradle tasks wire this in).

Quick start

Player setters follow Kotlin idiom — they return Unit, so they do not chain. Construct with Player(Config().apply { volume = 0.8f }) and call each setter on its own line.

Decode a file to PCM

Decoder streams a file through the Rockbox codec engine, yielding interleaved-stereo S16LE chunks one at a time — no output device required.
Codec state is process-wide — only one Decoder decodes at a time. Constructing a second Decoder blocks until the first is closed, so always keep decoders inside a use { } block (or call close()) before opening the next one.

API surface

Enums

  • EqPreset — 21 built-in presets: FLAT, ACOUSTIC, BASS_BOOST, BASS_REDUCER, CLASSICAL, DANCE, DEEP, ELECTRONIC, HIP_HOP, JAZZ, LATIN, LOUDNESS, LOUNGE, PIANO, POP, RNB, ROCK, SMALL_SPEAKERS, TREBLE_BOOST, TREBLE_REDUCER, VOCAL_BOOST.
  • RepeatModeOFF, ONE, ALL.
  • CrossfeedModeOFF, MEIER, CUSTOM.
  • ChannelModeSTEREO, MONO, CUSTOM, MONO_LEFT, MONO_RIGHT, KARAOKE, SWAP.
  • CrossfadeModeOFF, AUTO_SKIP, MANUAL_SKIP, SHUFFLE, SHUFFLE_OR_MANUAL, ALWAYS; MixModeCROSSFADE, MIX.
  • InsertPositionPREPEND, INSERT, INSERT_NEXT, INSERT_LAST, INSERT_SHUFFLED, INSERT_LAST_SHUFFLED, REPLACE, INDEX.
  • ReplayGainMode (player) — OFF, TRACK, ALBUM; DspReplayGainMode (Dsp) — TRACK, ALBUM, SHUFFLE, OFF.
The DSP chain mirrors Rockbox’s own Sound Settings — parametric EQ, crossfeed, tone controls, channel modes, surround, and the compressor. For what each knob does and sensible ranges, see the official Rockbox manual.

Notes

  • Rich values (metadata, player status) come back as Map<String, Any?>, parsed from the ABI’s JSON with org.json.
  • Sample buffers are ShortArray of interleaved-stereo signed 16-bit samples.
  • Native memory is freed automatically — handles are AutoCloseable (use { }), and every char* / int16* the ABI returns is freed inside the binding.
Two ReplayGain encodingsDspReplayGainMode (TRACK=0, ALBUM=1, SHUFFLE=2, OFF=3) for Dsp, ReplayGainMode (OFF=0, TRACK=1, ALBUM=2) for Player. See the overview.