gpt4 book ai didi

audio - 较新版本的 JRE 不加载音库,但旧版本会加载

转载 作者:搜寻专家 更新时间:2023-11-01 00:57:17 25 4
gpt4 key购买 nike

我有以下尝试加载音库的代码。我已经使用 JRE 1.6.03 和 1.6.43 在 Windows 7 上测试了代码。旧版本的 JRE (1.6.03) 工作正常,但新版本抛出异常。怎么回事?

public Main() {
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
BufferedInputStream soundBankStream = new BufferedInputStream(
getClass().getClassLoader().getResourceAsStream(
"soundbank.gm"));
synth.loadAllInstruments(MidiSystem.getSoundbank(soundBankStream));
} catch (MidiUnavailableException e) {
e.printStackTrace();
} catch (InvalidMidiDataException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

.

F:\>java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)

F:\>java -jar Test2.jar

F:\>"C:\Program Files\Java\jre6\bin\java.exe" -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)

F:\>"C:\Program Files\Java\jre6\bin\java.exe" -jar Test2.jar
javax.sound.midi.InvalidMidiDataException: cannot get soundbank from stream
at javax.sound.midi.MidiSystem.getSoundbank(Unknown Source)
at com.gulshansingh.test.Main.<init>(Main.java:24)
at com.gulshansingh.test.Main.main(Main.java:14)

您可以从这里下载音库:http://www.oracle.com/technetwork/java/soundbanks-135798.html

最佳答案

Java Sound API: Soundbanks 复制粘贴页

Java Sound API

This page provides different soundbanks which you can download and use with Java Sound. Soundbanks are necessary for correct operation of the internal software synthesizer that ships with Java Sound. By default, the Windows version of the J2RE does not ship with a soundbank, so you need to manually install one to use Java Sound's MIDI engine. Java Sound has a fallback mechanism that uses a hardware MIDI port if no soundbank is available, but it prevents reliable and consistent MIDI playback, so installation of a soundbank is recommended for Java Sound.

如您所见,Java Sound API 需要安装,因此如果您安装了较新的 JDK,则必须 redo the installation .

一个错误似乎与您的问题很接近:4887447 ,存在解决方法,但如果 banksound 在 JAR 中则不存在

关于audio - 较新版本的 JRE 不加载音库,但旧版本会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15996711/

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