我正在使用 Libgdx 编写游戏代码,它使用诸如 Gdx.files.internal("file") 之类的方法来加载文件,这在导出应用程序时应该可以工作,因为这就是它的本意
一些文件被复制到 USER 目录并从那里加载(音频)这是导致应用程序崩溃的原因吗?如此处所述:Java 应用程序在 Eclipse 中正常运行,但不是 .jar
如果有人能给我一个想法,那就太好了,它也不会为我启动 java 控制台,所以我不知道
编译后的 .jar 在这里:https ://www.dropbox.com/s/rz9v7lkdsj78z20/RUSHmup.jar (里面也有库)
这是我认为导致问题的音频加载代码(但我所看到的只是在 Eclipse 中可以正常工作并且可以正常工作的东西)
if(!Gdx.files.external("test.wav").exists()){
String f = copySong(FILE);
}
if(Gdx.files.external("test.wav").exists()) {
// String ss = copySong(FILE);
String songPath = Gdx.files.getExternalStoragePath() + Gdx.files.external("test.wav").path();
//System.out.println("B4: " + songPath);
songPath.replace('\\', '/');
//System.out.println("AF: " + songPath);
song = minim.loadFile(songPath,2048);//"C:/users/seantest/test.wav", 2048);
}
String external = Gdx.files.getExternalStoragePath();
external.replace('\\', '/');
Gdx.files.internal("data/audio/1.wav").copyTo(Gdx.files.external("1.wav"));
Gdx.files.internal("data/audio/2.wav").copyTo(Gdx.files.external("2.wav"));
Gdx.files.internal("data/audio/3.wav").copyTo(Gdx.files.external("3.wav"));
Gdx.files.internal("data/audio/go.wav").copyTo(Gdx.files.external("go.wav"));
count3 = minim.loadSample(external + "3.wav");
count2 = minim.loadSample(external + "2.wav");
count1 = minim.loadSample(external + "1.wav");
countGo = minim.loadSample(external + "go.wav");
audioData = new RSAudioData(this);
if(song!=null){
System.out.println("Song Info: " );
System.out.println(song.length() + " " + song.sampleRate() + " " + song.bufferSize());
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
beat.setSensitivity(300);
bl = new RSMBeatListener(beat, song);
fftLog = new FFT(song.bufferSize(), song.sampleRate());
fftLog.logAverages(22, 3);
max = new float[fftLog.avgSize()];
for(int i = 0; i < max.length-1; i++)
max[i] = 0;
}
}
public String copySong(String file) {
externalFile = Gdx.files.external("test.wav");
Gdx.files.internal(file).copyTo(externalFile);
exFile = Gdx.files.getExternalStoragePath() + "test.wav";
System.out.println(exFile);
return exFile;
}
public String sketchPath() {
return Gdx.files.getExternalStoragePath();
}