java 怎样支持mp3? java 怎样支持mp3? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://java.sun.com/products/java-media/jmf/mp3/download.html java播放mp3的代码:import javax.sound.sampled.AudioInputStream;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.AudioFormat;import javax.sound.sampled.Clip;import javax.sound.sampled.DataLine;import javax.sound.sampled.UnsupportedAudioFileException;import javax.sound.sampled.LineUnavailableException;import javax.sound.sampled.SourceDataLine;import java.io.IOException;import java.io.File;public class BasicPlayer { private AudioInputStream stream = null; private AudioFormat format = null; private Clip clip = null; private SourceDataLine m_line; public void play(File fileName,int itemStatus) { try { // From file stream = AudioSystem.getAudioInputStream(fileName); // At present, ALAW and ULAW encodings must be converted // to PCM_SIGNED before it can be played format = stream.getFormat(); if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { format = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), 16, format.getChannels(), format.getChannels() * 2, format.getSampleRate(), false); // big endian stream = AudioSystem.getAudioInputStream(format, stream); } // Create the clip DataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat(), AudioSystem.NOT_SPECIFIED); m_line = (SourceDataLine) AudioSystem.getLine(info); m_line.open(stream.getFormat(),m_line.getBufferSize()); m_line.start(); int numRead = 0; byte[] buf = new byte[m_line.getBufferSize()]; while ((numRead = stream.read(buf, 0, buf.length)) >= 0) { int offset = 0; while (offset < numRead) { offset += m_line.write(buf, offset, numRead-offset); } } m_line.drain(); m_line.stop(); m_line.close(); stream.close(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } } public double getDuration() { return m_line.getBufferSize() / (m_line.getFormat().getFrameSize() * m_line.getFormat().getFrameRate()); } public double getDecision() { return m_line.getMicrosecondPosition()/1000.0; }} 晕死,JAVA还能做什么,这么简单播放MP3的功能还要这么一大堆的源代码 晕~~~如果用网页来播放mp3的话就一行代码。。但是这样就可以说HTML比JAVA强吗??楼上的什么逻辑啊~~~~~ JAVA有个jmf包是专门支持音频,视频的 偶正在写一个mp3播放程序,是用jmf 大大虾帮我看看为什么copyOf报错了 Excel 和 SQL Server数据库 JAVA问题 BS结构 浏览器里 如何如何 有一个操作的菜单栏?? 怎样得到JTextArea里面某一行的数据? 弱弱的问一声:怎么查看A的Unicode编码? 为什么输出a是AB,而b是B java中有没有这样一个方法,就是当我的TEXTAREA的内容发生改变时触发一个事件 怎么学习java? jdk开发中设置系统环境变量有什么用? 八个J2EE的高级群,按层次划分,共享教程代码,期待各位朋友加入(需考试) 关于 heavy weight 和 light weight 重叠显示的问题!
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import java.io.IOException;
import java.io.File;public class BasicPlayer { private AudioInputStream stream = null;
private AudioFormat format = null;
private Clip clip = null;
private SourceDataLine m_line; public void play(File fileName,int itemStatus)
{
try {
// From file
stream = AudioSystem.getAudioInputStream(fileName); // At present, ALAW and ULAW encodings must be converted
// to PCM_SIGNED before it can be played
format = stream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
16,
format.getChannels(),
format.getChannels() * 2,
format.getSampleRate(),
false); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
} // Create the clip
DataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat(), AudioSystem.NOT_SPECIFIED);
m_line = (SourceDataLine) AudioSystem.getLine(info);
m_line.open(stream.getFormat(),m_line.getBufferSize());
m_line.start(); int numRead = 0;
byte[] buf = new byte[m_line.getBufferSize()];
while ((numRead = stream.read(buf, 0, buf.length)) >= 0) {
int offset = 0;
while (offset < numRead) {
offset += m_line.write(buf, offset, numRead-offset);
}
}
m_line.drain();
m_line.stop();
m_line.close();
stream.close();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
}
} public double getDuration()
{
return m_line.getBufferSize() /
(m_line.getFormat().getFrameSize() * m_line.getFormat().getFrameRate());
} public double getDecision()
{
return m_line.getMicrosecondPosition()/1000.0;
}
}
如果用网页来播放mp3的话就一行代码。。
但是这样就可以说HTML比JAVA强吗??楼上的什么逻辑啊~~~~~