:-) 비슷한 질문으로 모두를하는 데 도움이
흠. 이것은 내 물건에 대한 광고처럼 보일 수도 있지만, 당신은 여기 내 API를 사용할 수 있습니다
https://github.com/s4ke/HotSound
재생이 하나 매우 쉽습니다.
대안 : (나에 의해 약간의 변경) 클립 예를 들어
public static AudioInputStream getSupportedAudioInputStreamFromInputStream(InputStream pInputStream) throws UnsupportedAudioFileException,
IOException {
AudioInputStream sourceAudioInputStream = AudioSystem
.getAudioInputStream(pInputStream);
AudioInputStream ret = sourceAudioInputStream;
AudioFormat sourceAudioFormat = sourceAudioInputStream.getFormat();
DataLine.Info supportInfo = new DataLine.Info(SourceDataLine.class,
sourceAudioFormat,
AudioSystem.NOT_SPECIFIED);
boolean directSupport = AudioSystem.isLineSupported(supportInfo);
if(!directSupport) {
float sampleRate = sourceAudioFormat.getSampleRate();
int channels = sourceAudioFormat.getChannels();
AudioFormat newFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
sampleRate,
16,
channels,
channels * 2,
sampleRate,
false);
AudioInputStream convertedAudioInputStream = AudioSystem
.getAudioInputStream(newFormat, sourceAudioInputStream);
sourceAudioFormat = newFormat;
ret = convertedAudioInputStream;
}
return ret;
}
출처 : : 사용하는 Java 클립 (prebuffering)
... code ...
// specify the sound to play
File soundFile = new File("pathToYouFile");
//this does the conversion stuff for you if you have the correct SPIs installed
AudioInputStream inputStream =
getSupportedAudioInputStreamFromInputStream(new FileInputStream(soundFile));
// load the sound into memory (a Clip)
DataLine.Info info = new DataLine.Info(Clip.class, inputStream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(sound);
// due to bug in Java Sound, explicitly exit the VM when
// the sound has stopped.
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
event.getLine().close();
System.exit(0);
}
}
});
// play the sound clip
clip.start();
... code ...
은 그럼 당신은이 방법을 필요 http://www.java2s.com/Code/Java/Development-Class/AnexampleofloadingandplayingasoundusingaClip.htm
SPI는 클래스 패스에 .jars를 추가하여 추가됩니다.
는 MP3 이러한은 다음과 같습니다 (당신의 JDK와 함께 제공됩니다) 자바 FX를 사용
http://stackoverflow.com/questions/5667454/playing-audio-file-in-java-application?rq=1을 확인하십시오. 나는 mp3가 자바에 의해 지원되지 않는다는 것을 알고 있지만, .wma의 고려 윈도우는 아주 좋지 않다는 것을 알 수있다. – Austin