java音频播放

1. AudioInputStream input = AudioSystem.getAudioInputStream(File);

2. AudioFormat format = input.getFormat();

3. DataLine.Info info = new DataLine.Info(SourceDataLine.class,format);

4. SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);

5.line.open();

    line.start();

6. byte buf[] = new byte[1024];

while(true){

int i=input.read(buf);

if(i==-1){

break;

}

line.write(buf,0,buf.length);

}

7. line.drain();

    line.close();

你可能感兴趣的:(java)