gpt4 book ai didi

java - NullPointer异常GainControl

转载 作者:行者123 更新时间:2023-12-03 01:37:14 24 4
gpt4 key购买 nike

以下代码段应调节AAC播放器的音量:

private void decodeAndPlayAAC() {
SourceDataLine line = null;
byte[] b;
try {
stop = false;
final ADTSDemultiplexer adts = new ADTSDemultiplexer(url.openStream());
final Decoder dec = new Decoder(adts.getDecoderSpecificInfo());
final SampleBuffer buf = new SampleBuffer();
while (!stop) {
b = adts.readNextFrame();
//here the AACException for unexpected profile is thrown
dec.decodeFrame(b, buf);
FloatControl gainControl = null;

if (line == null) {
final AudioFormat audioFormat = new AudioFormat(buf.getSampleRate(), buf.getBitsPerSample(), buf.getChannels(), true, true);
line = AudioSystem.getSourceDataLine(audioFormat);
line.open();
gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
line.start();
addAudioDetails(audioFormat);
}
b = buf.getData();
line.write(b, 0, b.length);

int gainLevel = (int) ((int) gainControl.getMinimum() + ((gainControl.getMaximum() - gainControl.getMinimum()) / 100 * gainPercent));
gainControl.setValue(gainLevel);

}
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (AACException e) {
e.printStackTrace();
WebradioPlayer.getPlayer().getIcyReader().setInterrupted(true);
WebradioPlayer.setPlayer(null);
GUIHandler.getInstance().resetComponents();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (line != null) {
line.stop();
line.close();
stop = true;
GUIHandler.getInstance().resetComponents();
}
}
}

NullPointerException发生在gainControl处。当我在第一次“运行”中调试此代码时,gainControl存在,但在第二次运行中为null。
有人可以向我解释吗?

最佳答案

这真是令人尴尬:D,我不应该每次运行时都将增益控制设置为null...。

关于java - NullPointer异常GainControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51512705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com