Decoding MP3 files with JLayer

天涯浪子 提交于 2019-12-01 07:14:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!