我正在做一个项目,我将直接从 mp3 文件中解码数据,并将获得的 pcm 数据存储到 sdcard 中的临时文件夹 temp.pcm 中以供以后分析。我在解码数据时遇到问题......
//a short array to store raw pcm data
short[] buffer = new short[bufferSize];
ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
File filep = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/onenineoone.mp3");
InputStream inputStream = new BufferedInputStream(new FileInputStream(filep), 8 * 1024);
short[] pcm=null;
try
{
Bitstream bitstream = new Bitstream(inputStream);
boolean done = false;
while (!done)
{
javazoom.jl.decoder.Header frameHeader = bitstream.readFrame();
javazoom.jl.decoder.Decoder decoder = new javazoom.jl.decoder.Decoder;
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(frameHeader, bitstream);
****Log.i("decoder", "error in the samplebuffer??");****
if (output.getSampleFrequency() != 44100 || output.getChannelCount() != 1) throw new DecoderException("Stereo or non-44100 sampling rate .mp3 not supported", null);
pcm = output.getBuffer();
for (short s:pcm) {
outStream.write(s);
}
buffer=pcm;
}
done = true;
bitstream.closeFrame();
} catch (BitstreamException e) {
throw new IOException("Bitstream error: " + e);
} catch (DecoderException e) {
Log.w("error is:", "Decoder error", e);
}
**
已解决
我将私有 javazoom.jl.decoder.Decoder 解码器声明为全局键,但似乎它不会进入 SampleBuffer 的错误是我必须将其声明为 javazoom.jl.decoder.Decoder decoder = new javazoom.jl.decoder.解码器。