| 查看: 674 | 回复: 0 | ||
wangjing1377金虫 (小有名气)
|
[求助]
Java中添加音频文件 总是出错
|
|
package com.test2; import java.io.*; //import javax.sound.sampled.*; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; public class TestAudio { public static void main(String[] args) { // TODO Auto-generated method stub //1.先创建一个AePlayWave对象实例 AePlayWave apw = new AePlayWave("d:\\111.wav\\" ;//2.启动该线程并播放 apw.start(); } } //播放声音的类 class AePlayWave extends Thread { private String filename; public AePlayWave(String wavfile) { filename = wavfile; } public void run(){ File soundFile=new File(filename); AudioInputStream audioInputStream = null; try{ audioInputStream =AudioSystem.getAudioInputStream(soundFile); }catch(Exception e1){ e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); SourceDataLine auline=null; DataLine.Info info=new DataLine.Info(SourceDataLine.class, format); try{ auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); }catch(Exception e){ e.printStackTrace(); return; } auline.start(); int nBytesRead = 0; //这是缓冲 byte [] abData=new byte[1024]; try{ while(nBytesRead != -1){ nBytesRead=audioInputStream.read(abData, 0,abData.length); if(nBytesRead>=0) auline.write(abData, 0, nBytesRead); } }catch(IOException e){ e.printStackTrace(); return; }finally{ auline.drain(); auline.close(); } } } javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at com.test2.AePlayWave.run(TestAudio.java:32) |
» 猜你喜欢
售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急
已经有4人回复
我的“飞艇+直升机”专利中了VFS的TVF 2027,求高校师生带写论文并参会
已经有3人回复
27博士申请自荐-材料
已经有8人回复
售SCI文章,我:8O.5.5.1O.54,科目全,可十急
已经有8人回复
售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急
已经有8人回复
售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急
已经有8人回复
售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急
已经有12人回复
售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急
已经有6人回复
售SCI文章,我:8O.5.5.1O.54,科目全,可十急
已经有3人回复
售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急
已经有3人回复










;
回复此楼
10