我编写了一个加载 .wav 文件的应用程序,但它只加载一次。我希望能够在第一首曲目结束后重新加载 wav 文件。我怎样才能在 java 中做到这一点?另外,如果我在曲目结束后(加载所选曲目时)两次点击播放,它会抛出一个
IllegalThreadStateException.
if (threadStatus != 0 || this != me)
throw new IllegalThreadStateException();
我用来加载文件的代码是这样的:
OpenAL openal = new OpenAL();
source = openal.createSource(new File(Audioplayer.path));
System.out.println(source.toString());
source.play();
source.setGain(0.75f); // 75% volume
source.setPitch(0.85f); // 85% of the original pitch
source.setPosition(0, 0, 0); // -1 means 1 unit to the left
source.setLooping(false); // Loop the sound effect
j=source.getBuffer();
System.out.println(j);
for (i=1;i<=10000;i++){
Thread.sleep(1); // Wait for 10 seconds
}
Thread.sleep(10000); // Wait for 10 seconds
source.close();
openal.close();