나는 mp3plugin.jar 라이브러리를 사용하고 있으며 내 음악은 훌륭하게 작동합니다. 유일한 문제는 프로그램이 시작될 때 JFrame이 표시되지 않는다는 것입니다.음악 재생 중 JFrame이 표시되지 않습니까?
package com.org.pong;
import javax.sound.sampled.*;
import javax.sound.*;
import java.io.*;
import java.net.URL;
public class Music {
Music(String url) {
int total, totalToRead, numBytesRead, numBytesToRead;
byte[] buffer;
boolean stopped;
AudioFormat wav;
TargetDataLine line;
SourceDataLine lineIn;
DataLine.Info info;
File file;
FileInputStream fis;
// AudioFormat(float sampleRate, int sampleSizeInBits,
// int channels, boolean signed, boolean bigEndian)
wav = new AudioFormat(44100, 16, 2, true, false);
info = new DataLine.Info(SourceDataLine.class, wav);
buffer = new byte[1024 * 333];
numBytesToRead = 1024 * 333;
total = 0;
stopped = false;
if (!AudioSystem.isLineSupported(info)) {
System.out.print("no support for " + wav.toString());
}
try {
// Obtain and open the line.
lineIn = (SourceDataLine) AudioSystem.getLine(info);
lineIn.open(wav);
lineIn.start();
fis = new FileInputStream(file = new File(url));
totalToRead = fis.available();
while (total < totalToRead && !stopped) {
numBytesRead = fis.read(buffer, 0, numBytesToRead);
if (numBytesRead == -1)
break;
total += numBytesRead;
lineIn.write(buffer, 0, numBytesRead);
}
} catch (LineUnavailableException ex) {
ex.printStackTrace();
} catch (FileNotFoundException nofile) {
nofile.printStackTrace();
} catch (IOException io) {
io.printStackTrace();
}
}
}
그것이 내가이 이전 질문 post..try 사용에 OCUR 것 U 말했다고 재미는'그것은 재미 없어 – nachokk
을 SwingWorker'. 실제로 슬프다. –
@nachokk 죄송합니다. 나는 다른 스레드에 관심을 기울이지 않았다. –