问题描述
我知道这是一个已经被问到的问题,但我无法得到答案
我找到了这种播放声音的方式:
Clip sound = AudioSystem.getClip();
sound.open(AudioSystem.getAudioInputStream(new File("path/to/sound")));
sound.start();
但问题是我在游戏循环中运行这段代码,我想以某种方式构造它,这样我就不需要每次都从输入中读取声音,但已经将声音保存在内存中,所以我不必每次都加载它。
我尝试做这样的事情:
Clip sound = AudioSystem.getClip();
sound.open(AudioSystem.getAudioInputStream(new File("path/to/sound")));
while(true)
{
sound.start();
}
也喜欢这个
AudioStream audiostream = AudioSystem.getAudioInputStream(new File("path/to/sound"));
while(true)
{
Clip sound = AudioSystem.getClip();
sound.open(AudioSystem.getAudioInputStream(audiostream));
sound.start();
}
但它不起作用,或者它只起作用1次
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)