我的Java聲音播放以錯誤開始,但不播放聲音。Java聲音控制不起作用
我在網上搜索,但它仍然無法正常工作d:
可以請您幫助我理解我的問題解決+?
如果您需要更多的細節,代碼,轉儲,輸出,數據只是讓我知道。
Sound.java:
package com.itaysharon.questematic;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import com.itaysharon.questematic.enums.SoundOptions;
public class Sound {
public static Thread dj;
public static synchronized void playSound(final String url, SoundOptions mode) {
dj = new Thread(new Runnable() {
@Override
public void run() {
try {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("assets" + File.separator + url));
AudioSystem.getClip().open(inputStream);
AudioSystem.getClip().setFramePosition(0);
switch(mode) {
case Stop:
AudioSystem.getClip().stop();
break;
case Play:
AudioSystem.getClip().start();
break;
case Loop:
AudioSystem.getClip().loop(Clip.LOOP_CONTINUOUSLY);
break;
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
});
if (mode != SoundOptions.Stop) {
dj.start();
} else {
try {
AudioSystem.getClip().stop();
AudioSystem.getClip().close();
dj.interrupt();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
SoundOptions.java:
package com.itaysharon.questematic.enums;
public enum SoundOptions {
Play, Loop, Stop;
}
請你分享錯誤消息 –
沒有錯誤消息,它只是不播放wav文件 –
純java和沒有特殊的庫 –