想用java作一个播放器。。高手进来指点一下…… RT 能不能实现播放mp3文件?用什么函数?高手给指点一下。先谢了…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这里http://java.ccidnet.com/art/5179/20060317/482627_1.html有个现成可以下载.你研究下吧 如果音频数据是压缩格式的,如MP3或Ogg,必须先进行一次转换——把MP3/Ogg解码成PCM。解码主要包括三个步骤: 1、创建一个解压缩结果的定制AudioFormat(PCM编码),但保留和原压缩流一样的取样率、通道信息等。 2、创建一个AudioInputStream把原来的AudioInputStream转换成新的AudioFormat格式。 3、获得一个处理解码后格式的SourceDataLine。 如下所示: AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,baseFormat.getSampleRate(),16,baseFormat.getChannels(),baseFormat.getChannels() * 2,baseFormat.getSampleRate(),false);ais = AudioSystem.getAudioInputStream(decodedFormat, ais);line = getLine(decodedFormat); getLine()方法的返回值是一个与参数中指定的AudioFormat兼容的SourceDataLine。如果不能获得兼容的SourceDataLine,getLine()返回null。在getLine()方法中,我们首先创建和填充一个DataLine.Info结构,调用AudioSystem.getLine()方法,将info结构传递给AudioSystem类工厂。 private SourceDataLine getLine(AudioFormat audioFormat) {SourceDataLine res = null;DataLine.Info info = new DataLine.Info(SourceDataLine.class,audioFormat);try {res = (SourceDataLine) AudioSystem.getLine(info);res.open(audioFormat);}catch (Exception e) {}return res;} 准备好AudioInputStream和SourceDataLine之后,playMusic()剩余的任务已经很简单:用一个循环从AudioInputStream读取数据,然后写入到SourceDataLine。 int inBytes = 0;while ((inBytes != -1) && (!stopped) && (!threadExit)) {try {inBytes = ais.read(audioData, 0, BUFFER_SIZE);}catch (IOException e) { e.printStackTrace(); }if (inBytes >= 0) {int outBytes = line.write(audioData, 0, inBytes);}if (paused) waitforSignal();} java正则表达式问题..新人在线求帮助 想写一个JAVA WEB 程序玩玩,可是却坐了一天也没弄出来 java字符串排序 JDialog 如何控制最大 size? JavaScript 题目 哪有LookAndFeel下载?并怎样把它运用到自己的程序中? 哪里有JBuilder 7下载??(含注册码的)(请进) 大家说接口可以直接产生对象吗? 请问怎样安装JDBC FOR SQL SERVER?怎样判断安装成功? 求一个java正则表达式 java新手? JAVA是如何体现OOP的
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
ais = AudioSystem.getAudioInputStream(decodedFormat, ais);
line = getLine(decodedFormat); getLine()方法的返回值是一个与参数中指定的AudioFormat兼容的SourceDataLine。如果不能获得兼容的SourceDataLine,getLine()返回null。在getLine()方法中,我们首先创建和填充一个DataLine.Info结构,调用AudioSystem.getLine()方法,将info结构传递给AudioSystem类工厂。 private SourceDataLine getLine(AudioFormat audioFormat) {
SourceDataLine res = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class,
audioFormat);
try {
res = (SourceDataLine) AudioSystem.getLine(info);
res.open(audioFormat);
}
catch (Exception e) {
}
return res;
}
准备好AudioInputStream和SourceDataLine之后,playMusic()剩余的任务已经很简单:用一个循环从AudioInputStream读取数据,然后写入到SourceDataLine。 int inBytes = 0;
while ((inBytes != -1) && (!stopped) && (!threadExit)) {
try {
inBytes = ais.read(audioData, 0, BUFFER_SIZE);
}
catch (IOException e) { e.printStackTrace(); }
if (inBytes >= 0) {
int outBytes = line.write(audioData, 0, inBytes);
}
if (paused) waitforSignal();
}