Albatross
Albatross

Reputation: 71

Decoding MP3 files with JLayer

I want to use JLayer to decode an MP3 file. I have searched and searched for documentation and examples on how exactly to do this, and have turned up nothing of use. Everything I find is embedded in other examples or references JavaSound, which is unacceptable in my case.

I feel like this is incredibly easy, but I can't figure out how to do it. I don't know what the parameters are for

Decoder decoder = new Decoder();
decoder.decodeFrame(Header header, Bitstream stream);

or how to obtain them.

tl;dr How do I decode an MP3 file with nothing but JLayer? No MP3 SPI, JavaSound, Tritonus--nothing.

Upvotes: 3

Views: 5677

Answers (1)

Albatross
Albatross

Reputation: 71

Figured it out myself.

Bitstream bitStream = new Bitstream(new FileInputStream("path/to/audio.mp3"));

while(condition){
    Decoder decoder = new Decoder();
    int[] samples = decoder.decodeFrame(bitStream.readFrame(), bitStream); //returns the next 2304 samples
    bitStream.closeFrame();

    //do whatever with your samples
}

Upvotes: 4

Related Questions