Java에서 재생하는 여러 .wav 파일이 있습니다. 이 제거 된 예제에서 "똑 (drip)"소리는 들릴 수 있지만 같은 코드를 통해 실행 되더라도 "swish"는 아닙니다. "swish"에 대해 특별한 점이없는 것 같습니다 : Gnome 데스크탑에서 재생됩니다. 비슷한 응용 프로그램을 가지고 있지만, "휙휙"깎아 내린 것이 아니라 "똑똑한"것이 아니라 데이터의 성격에 문제가있는 것 같지 않습니다.Java AudioSystem .wav 파일의 동작이 일치하지 않습니다.
아이디어가 있습니까? 이 버그는 작동중인 것으로 알려진 코드가 재 구축 된 시스템에서 "재배포"된 후 발견되었습니다 : 우분투 10.10 및 Eclipse Indigo 다시 설치. 이 버그는 Sun JDK 6과 OpenJDK 6 모두에서 발생합니다. 수정 된 시스템은 실제로는 하드웨어가 다릅니다. Intel E6500 (2 코어, 2.93 GHz) 우분투, Eclipse, OpenJDK, Sun JDK 만 설치했습니다. 이전 시스템은 우분투, 이클립스, OpenJDK (AMD의 630 (4 코어, 2.8GHz))였습니다.
편집 실험을 마친 후로드 된 첫 번째 클립이 작동하는 것으로 보입니다. TestSounder 생성자는 순서를 바꿀 수있는 위치에로드합니다. 아마도 정적 메서드 AudioSystem.getLine
의 사용은 분명히 비 객체 지향 작업이기 때문에 여기와 관련이 있습니다.
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Clip;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.LineUnavailableException;
public class TestSounder
{
String resourcePathFromBin = "/resources/";
Clip dripClip;
Clip swishClip;
public TestSounder()
{
dripClip = setupClip("drip.wav");
swishClip = setupClip("swish.wav");
}
public void close()
{
dripClip.close();
swishClip.close();
}
private Clip setupClip(String fileName)
{
Clip clip = null;
try
{
AudioInputStream ais =
AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream(resourcePathFromBin +
fileName));
AudioFormat af = ais.getFormat();
DataLine.Info lineInfo = new DataLine.Info(Clip.class, af);
clip = (Clip)AudioSystem.getLine(lineInfo);
clip.open(ais);
}
catch (UnsupportedAudioFileException e)
{
assert false: "bug";
}
catch (IOException e)
{
assert false: "bug";
}
catch (LineUnavailableException e)
{
assert false: "bug";
}
return clip;
}
public void go(UtilityK.Sounds s)
{
Clip clip = null;
if (s == UtilityK.Sounds.drip)
clip = dripClip;
if (s == UtilityK.Sounds.swish)
clip = swishClip;
clip.stop();
clip.setFramePosition(0);
clip.start();
//while (clip.isRunning())
// TestSounder.delay();
}
public static void main(String[] args)
{
TestSounder obj = new TestSounder();
obj.go(UtilityK.Sounds.swish);
TestSounder.delay();
obj.go(UtilityK.Sounds.drip);
TestSounder.delay();
obj.go(UtilityK.Sounds.swish);
TestSounder.delay();
obj.go(UtilityK.Sounds.drip);
TestSounder.delay();
obj.close();
}
private static void delay()
{
Thread.sleep(5000);
}
}
public interface UtilityK
{
enum Sounds { drip, swish };
}
2 개의 WAV는 어떤 인코딩 및 형식입니까? BTW - 모든 catch에 대해 'e.printStackTrace()'를 호출합니다. –
@Andrew Thompson, 웹 서비스를 사용하여 일부 사운드를 .wav로 변환했습니다. 원래 형식이 무엇인지는 기억이 안납니다. 11 개의 파일이 있고 모두 이전 컴퓨터에서 동일한 소스 코드로 작업했습니다. – H2ONaCl
.. 그리고 그 WAVs를 열 때 스택 추적의 출력은 무엇입니까? –