首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 播发声音文件

2013-11-08 
java 播放声音文件// 1. Access the audio file as a stream??? AudioInputStream stream AudioSystem.g

java 播放声音文件

// 1. Access the audio file as a stream
??? AudioInputStream stream = AudioSystem.getAudioInputStream(
??????????????????????????????????? getClass( ).getResource(fnm) );
??

??? // 2. Get the audio format for the data in the stream
??? AudioFormat format = stream.getFormat( );

??? // 3. Gather information for line creation
??? DataLine.Info info = new DataLine.Info(Clip.class, format);

??? // 4. Create an empty clip using that line information
??? Clip clip = (Clip) AudioSystem.getLine(info);

??? // 5. Start monitoring the clip's line events
??? clip.addLineListener(this);

??? // 6. Open the audio stream as a clip; now it's ready to play
??? clip.open(stream);
??? stream.close( );

热点排行