沒問題,所以我有這段代碼,它在Eclipse中播放時正在工作。但是當我導出它時,它根本不會播放任何聲音..我應該如何導出它,或者我應該怎麼做才能使其工作?製作Java遊戲時出現一個小錯誤
package sound;
import java.io.InputStream;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class GameSounds
{
public static synchronized void hit()
{
try
{
String resPath = "/sounds/8bit_bomb_explosion.wav"; // *** this is the key ***
InputStream audioInStream = GameSounds.class.getResourceAsStream(resPath);
System.out.println("is audioInStream null?: " + (audioInStream == null)); // test it!
AudioInputStream inputStream = AudioSystem.getAudioInputStream(audioInStream); Clip clip = AudioSystem.getClip();
clip.open(inputStream);
clip.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
沒有錯誤..我認爲這個問題是出口..我只是按出口,然後我選擇可執行的JAR文件..一切正常,但音頻不..
和有沒有例外拋出
通過記錄輸出你的意思是「audioInStream null?」如果是,則輸出爲假 並且沒有拋出異常
那麼你的日誌輸出是什麼?並且拋出異常? –
1)爲了更好地提供幫助,請發佈[SSCCE](http://sscce.org/)。 2)請在句子開頭添加大寫字母。還要爲單詞I使用大寫字母,並使用JEE或WAR等縮寫詞和首字母縮略詞。這使人們更容易理解和幫助。 –
檢查你的jar的內容。它是否包含文件'sounds'下的文件'8bit_bomb_explosion.wav'?請記住,jar文件只是一個擴展名爲.jar的zip文件。 –