问题
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.
回答1:
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
}
来源:https://stackoverflow.com/questions/12099114/decoding-mp3-files-with-jlayer