sun.audio API에서 .wav 파일이 지원되는 파일 임에도 불구하고 분명히 내가 갖고 있었던 파일이 아니어야합니다. .aiff 파일은 현재 작동하지만이 방법으로는 더 좋은 방법은 찾지 못했습니다.Java 프로그램에서 소리 재생 만들기
String strFilename = "C:\\Documents and Settings\\gkehoe\\Network\\GIM\\Explode.aiff";
File soundFile = new File(strFilename);
AudioInputStream audioInputStream = null;
try
{
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
}
catch (Exception e)
{
e.printStackTrace();
}
AudioFormat audioFormat = audioInputStream.getFormat();
SourceDataLine line = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class,
audioFormat);
try
{
line = (SourceDataLine) AudioSystem.getLine(info);
/*
The line is there, but it is not yet ready to
receive audio data. We have to open the line.
*/
line.open(audioFormat);
}
catch (LineUnavailableException e)
{
e.printStackTrace();
System.exit(1);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
line.start();
int nBytesRead = 0;
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
while (nBytesRead != -1)
{
try
{
nBytesRead = audioInputStream.read(abData, 0, abData.length);
}
catch (IOException e)
{
e.printStackTrace();
}
if (nBytesRead >= 0)
{
int nBytesWritten = line.write(abData, 0, nBytesRead);
}
}
line.drain();
/*
All data are played. We can close the shop.
*/
line.close();
이 광고를 보았습니까 http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java#comment4884807_26311? – Mob
네,하지만이 코드를 가지고있는 것은 제가 한 것입니다. 그것은 작동하지 않습니다. –
질문이 있으십니까? –