JNI Android wrapper for encoding and decoding ogg/vorbis bitstreams
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


libvorbis - Vorbis Encoder/Decoder example for Android/JNI

libvorbis - Vorbis Encoder/Decoder example for Android/JNI.


  • The purpose of this project is to demonstrate how Android can use a JNI wrapper around the libvorbis library to both encode PCM data, and decode a ogg/vorbis bitstream


  • Press the "Start Recording" button to start recording, then press the "Stop Recording" button to stop recording.
  • Recorded content is saved saveTo.ogg on the external storage location.
  • Press the "Start Playing" button to start playing the recorded data, then press the "Stop Playing" button to stop playing or simply wait for the playback to finish on its own.
  • Content is played form saveTo.ogg on the external storage location

To Build

  • Verify the ndk-build tool is in your path and simply execute ./build_jni.sh from your terminal

Library Usage

  • Encoder
  • To record to a file
VorbisRecorder vorbisRecorder = new VorbisRecorder(fileToSaveTo, recordHandler);

//Start recording with a sample rate of 44KHz, 2 channels (stereo), at 0.2 quality
vorbisRecorder.start(44100, 2, 0.2f);

//Start recording with a sample rate of 44KHz, 2 channels (stereo), at 128 bitrate
vorbisRecorder.start(44100, 2, 128000);
  • To read from other input, create a custom EncodeFeed
EncodeFeed encodeFeed = new EncodeFeed() {
             public long readPCMData(byte[] pcmDataBuffer, int amountToWrite) {
                 //Read data from pcm data source

             public int writeVorbisData(byte[] vorbisData, int amountToRead) {
                 //write encoded data to where ever

             public void stop() {
                 //The native encoder has finished

             public void stopEncoding() {
                 //The encoder should wrap up until the native encoder calls stop()

             public void start() {
                 //The native encoder has started
VorbisRecorder vorbisRecorder = new VorbisRecorder(encodeFeed, recordHandler);
  • Decoder
  • Decode from file
VorbisPlayer vorbisPlayer = new VorbisPlayer(fileToPlay, playerHandler);
  • To write to custom output, create a custom DecodeFeed
DecodeFeed decodeFeed = new DecodeFeed() {
             public int readVorbisData(byte[] buffer, int amountToWrite) {
                 //Read from vorbis data source

             public void writePCMData(short[] pcmData, int amountToRead) {
                 //Write encoded pcm data

             public void stop() {
                 //Stop called from the native decoder

             public void startReadingHeader() {
                 //Called from the native decoder to read header information first

             public void start(DecodeStreamInfo decodeStreamInfo) {
                 //Called from the native decoder that we're ready and have processed the header information
VorbisPlayer vorbisPlayer = new VorbisPlayer(decodeFeed);


  • For simplicity sake, this code is licensed under the same license as the libvorbis library from (http://xiph.org/vorbis/)


  • Tested and working under the Nexus 4, feedback for other devices are welcome
  • Pull requests welcome