各位大虾们,急求解决,在执行音频文件出现异常。
//播放音频文件
public void play(){
String fileurl = "e:\\xxx.wav";
try{
InputStream in=new FileInputStream(new File(fileurl));
BufferedInputStream sb=new BufferedInputStream(in);
AudioInputStream ais = AudioSystem.getAudioInputStream (sb);
AudioFormat aif = ais.getFormat();
SourceDataLine sdl = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class,aif);
sdl = (SourceDataLine)AudioSystem.getLine(info);
sdl.open(aif);
sdl.start();
//play
int nByte = 0;
byte[] buffer = new byte[128];
while(nByte != -1){
nByte = ais.read(buffer,0,128);
if(nByte >= 0){
int oByte = sdl.write(buffer, 0, nByte);
System.out.println(oByte);
}
}
sdl.stop();
}catch(UnsupportedAudioFileException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
在运行时 这段代码《AudioInputStream ais=AudioSystem.getAudioInputStream (sb);》出现异常如下:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1102)
at test.AudioDemo.play(AudioDemo.java:31)
at test.AudioDemo.main(AudioDemo.java:93)
有谁遇到过没,各位大虾帮忙指点迷津。不胜感激!