gpt4 book ai didi

java - JAVA- jar 导出后声音未播放

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

我有一个问题,在导出我的Java项目后,没有声音在播放。

我在互联网上搜索后发现:Main.class.getResourceAsStream("fileloc");解决了这个问题

但是我类用的是这个
哪里有问题?

public class Sounds {

private static Clip eat;
public static Clip collect;
private static Clip lsd;
private static AudioInputStream inputStream;
private static FloatControl gainControl;

public static void getSounds(){
try{
eat = getClip("/sound/collect/eat.wav");
collect = getClip("/sound/collect/collect.wav");
lsd = getClip("/sound/LSD.wav");
} catch(LineUnavailableException | UnsupportedAudioFileException| IOException e){
e.printStackTrace();
}
}

private static Clip getClip(String loc) throws LineUnavailableException, UnsupportedAudioFileException, IOException{
Clip c = AudioSystem.getClip();
inputStream = AudioSystem.getAudioInputStream(Spielfeld.class.getResourceAsStream(loc));
c.open(inputStream);
gainControl = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(+6.0f);
c.setMicrosecondPosition(0);
return c;
}

public static void playSound(final String url) {
switch(url){
case "collect/collect.wav": collect.start(); collect.setMicrosecondPosition(0); break;
case "collect/eat.wav": eat.start(); eat.setMicrosecondPosition(0); break;
case "LSD.wav": lsd.start(); lsd.setMicrosecondPosition(0); break;
}
}
}

谢谢您的帮助

最佳答案

关于java - JAVA- jar 导出后声音未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252251/

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