2013-04-16 3 views
5

내 응용 프로그램에 문제가 있습니다. 이클립스에서 앱을 실행할 때 소리가 잘 들리지만 실행 가능한 항아리로 앱을 내 보내면 소리가 나지 않는다. 사운드가 재생됩니다병으로 보내기 한 후 소리가 들리지 않습니다.

방법 :

public static synchronized void playSound() 
    { 
      new Thread(new Runnable() 
      { 
       // The wrapper thread is unnecessary, unless it blocks on the 
       // Clip finishing; see comments. 
       public void run() 
       { 
        try 
        { 
         Clip clip = AudioSystem.getClip(); 
         AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav")); 
         clip = AudioSystem.getClip(); 
         clip.open(inputStream); 
         clip.start(); 
        } 
        catch (Exception e) 
        { 
         System.err.println(e.getMessage()); 
        } 
       } 
      }).start(); 
     } 

실수가 될 수 있습니까?

+1

파도 파일이 JAR에 있습니까? –

+0

jar 파일의 압축을 풀어보고 파일을 찾았습니다. – Sk1X1

답변

6

문제는 JAR 파일이

AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("sound.wav")); 

어떤 이유로 getResourceAsStream 작동하지 않습니다에 있습니다. 따라서 이것을 getResource으로 바꿉니다.

AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResource("sound.wav")); 

으로 바꿉니다.

+0

도 똑같은 문제가 있었고 이것이 나를 위해 일했습니다. 너 대 남자. – kwikness

+0

와우 이상한 – Ajay

관련 문제