package SST.com.tw;
import java.io.*;
import javax.sound.sampled.*;
public class AP_Main {
static ByteArrayOutputStream bos = new ByteArrayOutputStream();
public static void main(String args[]) {
try {
File file = new File ("D:\\aa.au");
InputStream in = new FileInputStream(file);
AudioInputStream AIS = AudioSystem.getAudioInputStream(file);
AudioFormat format = AIS.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format);
line.start();
int bufferSize = (int) format.getSampleRate() * format.getFrameSize();
byte[] buffer = new byte[bufferSize];
try {
int bytesRead = 0;
while (bytesRead >= 0) {
bytesRead = AIS.read(buffer, 0, buffer.length);
if (bytesRead >= 0) {
line.write(buffer, 0, bytesRead);
}
}
} catch (IOException e) {
System.out.println("" + e.toString());
}
line.close();
System.out.println("program over");
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
- Sep 15 Wed 2010 14:36
J2SE 實現放音功能(使用 sound API)
全站熱搜
留言列表