Java-播放WAV音频
来源:互联网 发布:上海软件培训机构 编辑:程序博客网 时间:2024/04/29 06:23
public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub AePlayWave apw=new AePlayWave("aaa.wav"); 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[512]; 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(); } }}
0 0
- Java-播放WAV音频
- java 播放wav格式音频
- 播放WAV音频
- 使用OSS播放WAV音频
- Wav 格式音频播放实例
- SDL播放wav音频分析
- 使用openal播放WAV音频
- 使用openal播放WAV音频
- JAVA 播放WAV格式文件
- java 播放 wav 声音文件
- C# winform播放wav格式音频
- 单片机播放WAV格式音频的理解
- WAV音频的播放(带窗口)
- c++音频播放,wav格式的
- java 播放midi,wav,mp3
- java 播放midi,wav,mp3
- windows播放wav声音文件--java播放wav完整demo
- JAVA画出wav音频波形图
- Java中static的特点
- Android中HttpUrlConnection使用步骤与总结
- 旋转变换(二)欧拉角
- nodejs 使用async进行BT吧最新电影数据爬取
- 工作杂记
- Java-播放WAV音频
- 【面试】JSP构架模型
- Linux 上的基础网络设备详解
- LinkSpark日报|人工智能资料库
- JUnit4中@AfterClass @BeforeClass @after @before介绍
- 【面试】SP隐含变量(也叫做内置对象、内建对象等等)这些东西在JSP当中,不用声明直接使用。
- 微信-创建微信公众号(2)
- 使用客户端连接ubuntu上的mysql Can't connect to MySQL server on 'ubuntu'(10061)
- C# API学习小例子