5 개의 wav 파일이 있습니다. sourceDataLine을 사용하여 단일 Java 프로그램에서 순차적으로 재생하려고합니다. 그러나 제 프로그램은 올바른 순서를 유지하지 못합니다. 누구나 나를 코드 세그먼트를 제공 할 수 있습니까?자바에서 사운드 재생
0
A
답변
3
Documentation을 확인 했습니까?
는 here에서이 예제를 시도 :import java.io.*;
import javax.sound.sampled.*;
/**
* Use SourceDataLine to read line-by-line from the external sound file.
*/
public class SoundLineTest {
public static void main(String[] args) {
SourceDataLine soundLine = null;
int BUFFER_SIZE = 64*1024; // 64 KB
// Set up an audio input stream piped from the sound file.
try {
File soundFile = new File("gameover.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
AudioFormat audioFormat = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
soundLine = (SourceDataLine) AudioSystem.getLine(info);
soundLine.open(audioFormat);
soundLine.start();
int nBytesRead = 0;
byte[] sampledData = new byte[BUFFER_SIZE];
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(sampledData, 0, sampledData.length);
if (nBytesRead >= 0) {
// Writes audio data to the mixer via this source data line.
soundLine.write(sampledData, 0, nBytesRead);
}
}
} catch (UnsupportedAudioFileException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
} finally {
soundLine.drain();
soundLine.close();
}
}
}
관련 문제
- 1. 사운드 카드가없는 SIP에서 사운드 재생
- 2. Android, 사운드 풀에서 사운드 재생
- 3. 자바에서 호출 된 AS3에서 한 번에 하나의 사운드 재생
- 4. 특정 장치에서 사운드 재생
- 5. 사소한 리눅스 사운드 재생
- 6. 기본 사운드 재생
- 7. 보기로드시 사운드 재생
- 8. iOS에서 오버랩 사운드 재생
- 9. Chrome에서 여러 사운드 재생
- 10. MediaPlayer로 SDCard에서 사운드 재생?
- 11. Xcode로 무작위 사운드 재생
- 12. iis 7 재생 사운드
- 13. 모든 컴퓨터에서 사운드 재생
- 14. 두 번째 사운드 재생
- 15. 사운드 재생 사이의 지연?
- 16. MATLAB : 사운드 재생 중지
- 17. WP7에서 사운드 루프 재생
- 18. Android에서 Ogg 사운드 재생
- 19. Symbian S60에서 사운드 재생
- 20. 관리 코드로 사운드 재생
- 21. C++에서 사운드 재생
- 22. FMOD에서 단순한 사운드 재생
- 23. 재생 사운드 캡처
- 24. cocos2d 게임에서 사운드 재생
- 25. 사운드 재생 프로그램
- 26. 힌트 사운드 재생
- 27. iphone/android에서 사운드 재생
- 28. 동시에 여러 사운드 재생
- 29. 생성 된 사운드 재생
- 30. AX09에서 사운드 재생
번호가 우리를보기 ** 당신의 ** 코드를. –
더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. 5 사운드 샘플이 아닌 2 사운드 샘플로 만들지 만, –