바이트 배열을 서버에서 수신 했으므로 연결되어 완벽하게 전송된다는 것을 알고 있습니다. 바이트 배열에서 사운드를 재생하려고 할 때입니다.바이트 배열에서 사운드 재생
다음은 사운드를 재생해야하는 이유입니다.
SourceDataLine speaker = null;
try {
DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class, getAudioFormat(samplerate));
speaker = (SourceDataLine) AudioSystem.getLine(speakerInfo);
} catch (LineUnavailableException e) {
e.printStackTrace();
}
int nBytesRead = 0;
while (nBytesRead != -1) {
if (nBytesRead >= 0) {
speaker.write(bytes, 0, nBytesRead);
}
}
getAudioFormat :
private AudioFormat getAudioFormat(float sample) {
int sampleSizeBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sample, sampleSizeBits, channels, signed, bigEndian);
}
가 어떻게이 byte[]
에서 음악을 재생할 수 있습니다?
'Byte []'또는'byte []'를 의미합니까? –
그들은 비교적 동일합니다 ...하지만 나는 [byte]를 의미합니다. – KeirDavis
아니요, 이들은 동일하지 않습니다. 'Byte []'는'java.lang.Byte' 타입의 참조 배열이고'byte []'는 원시 8 비트 부호있는 정수 값의 배열입니다. –