1
나는 오디오 클립을 재생하기 위해 다음과 같은 방법이 : 나는 (레노버) 윈도우 7 데스크톱 플랫폼에서이 작업을 실행하면 예상대로자바 오디오 스트림 플랫폼 독립적 인
public static synchronized void playSound(final String path) {
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(
this.getClass().getClassLoader().getResourceAsStream(path));
clip.open(inputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
while (runThread) {
Thread.sleep(5000);
}
clip.stop();
}
catch (Exception e) {
System.err.println("Audio clip error: "+e.getMessage());
e.printStackTrace();
}
}
}).start();
}
이 작동합니다. 그러나, 윈도우 7 노트북 (에이서)에서 실행하면 다음과 같은 예외가 발생합니다 :
java.lang.NullPointerException
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at StokerMonitor.Alerts$1.run(Alerts.java:62)
at java.lang.Thread.run(Unknown Source)
라인 62는 'AudioInputStream'문입니다. 두 플랫폼간에 차이점이 무엇인지 모르겠지만 랩톱에없는 일부 Windows 7 종속성이 있어야합니다. 누구든지 어떤 제안이 있습니까? TIA.
'this.getClass(). getClassLoader(). getResourceAsStream (path)'가 null을 리턴합니다. .jar에 실제로 해당 경로와 일치하는 항목이 있는지 확인하십시오. getResourceAsStream *은 파일 이름을 인수로 취하지 않으며, 모든 플랫폼에서 디렉토리 분리 자로 슬래시 ('/')를 사용해야하는 상대 URL (스키마 또는 권한 없음)을 사용합니다. – VGR
두 플랫폼 모두에서 동일한 jar입니다. 변수 'path'는 잘못된 이름입니다. .wav 파일 이름 일뿐입니다. –
'path'의 값은 무엇입니까? – VGR