Java 声音在eclipse中可以完美地加载和播放,但在转换为可运行的jar时会卡住
我正在制作一个游戏,但在导出它之后,我发现我的声音停止了我的游戏。线程暂停。以下是我在key listener类中所做的工作:Java 声音在eclipse中可以完美地加载和播放,但在转换为可运行的jar时会卡住,java,eclipse,audio,jar,slick,Java,Eclipse,Audio,Jar,Slick,我正在制作一个游戏,但在导出它之后,我发现我的声音停止了我的游戏。线程暂停。以下是我在key listener类中所做的工作: //creating a bullet handler.addObject(new PlayerShot1(tempObject.getX() + 58, tempObject.getY(), Id.PlayerShot1)); //changing variable to play sound Player.shooting = true; 在我的玩家课上: //c
//creating a bullet
handler.addObject(new PlayerShot1(tempObject.getX() + 58, tempObject.getY(), Id.PlayerShot1));
//changing variable to play sound
Player.shooting = true;
在我的玩家课上:
//called every time the spacebar is pressed
if(shooting) {
GetAudio.getSound("playerShot1").play(2.0f, 0.1f);
shooting = false;
}
我已经注释掉了GetAudio。。。。然后它又开始工作了。以防万一,下面是我的GetAudio类:
public class GetAudio {
public static Map<String, Sound> soundMap = new HashMap<String, Sound>();
public static Map<String, Music> musicMap = new HashMap<String, Music>();
public static void get() {
try {
soundMap.put("playerShot1", new Sound("./resources/sounds/playerShot1.ogg"));
} catch (SlickException e) {
e.printStackTrace();
}
}
public static Music getMusic(String key) {
return musicMap.get(key);
}
public static Sound getSound(String key) {
return soundMap.get(key);
}
}
公共类GetAudio{
public static Map soundMap=new HashMap();
公共静态映射musicMap=newhashmap();
公共静态void get(){
试一试{
soundMap.put(“playerShot1”,新声音(“/resources/sounds/playerShot1.ogg”);
}接住(滑溜){
e、 printStackTrace();
}
}
公共静态音乐getMusic(字符串键){
返回musicMap.get(键);
}
公共静态声音getSound(字符串键){
返回soundMap.get(键);
}
}
提前感谢您的帮助 不要使用
“/resources/sounds/…”
,而是使用“/sounds”
,并将资源作为源文件夹。根据项目文件夹的设置方式,可能会移动一些文件。使用WinRar之类的工具浏览jar文件,查看jar将文件放置在何处。我知道它正在查找声音,因为还有其他声音可以工作。问题出在这里新声音(“/resources/sounds/playerShot1.ogg”)
您使用的是eclipse可以找到的相对路径,但不是在jar中,请检查一下,也许这更清晰我可以从那里加载图像,为什么不能加载我的声音?