‘壹’ java 怎么读取mp3文件的信息,比如:歌曲名称,专辑名称,歌手,备注等信息
JDK本身是不支持mp3格式的。不过网上有提供JAR包下载,导入就可以了。
‘贰’ java如何读取MP3格式文件的内容然后对其播放实例代码
直接下个JMF,google搜,sun官网上有~~然后安装目录是你的JDK,
再播放MP3文件就:
import javax.media.*;
import java.net.MalformedURLException;
import java.net.URL;
Player player;
File playFile=new File("");//你的MP3文件
try {
player=Manager.createRealizedPlayer(playFile.toURL());
player.prefetch();
player.setMediaTime(new Time(10.0));
player.start();
} catch (NoPlayerException e1)
{
e1.printStackTrace();
} catch (CannotRealizeException e1)
{
e1.printStackTrace();
} catch (MalformedURLException e1)
{
e1.printStackTrace();
} catch (IOException e1)
{
e1.printStackTrace();
}
这种基本代码,自己搜一下,用编译器熟悉熟悉JMF的方法就会了。。。我以前回答别人时的答案~~~
‘叁’ java 如何读写远程mp3文件
//:URLReader.java ==================
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URL;
public class URLReader {
public static void readAndSave(String url,String fileFullName)throws Exception{
System.out.println("Starting.");
URL u = new URL(url);
byte[] buffer = new byte[1024*8];
int read;
int ava = 0;
long start = System.currentTimeMillis();
BufferedInputStream bin = new BufferedInputStream(u.openStream());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(fileFullName));
while((read=bin.read(buffer))>-1){
bout.write(buffer,0,read);
ava+=read;
long speed = ava/(System.currentTimeMillis()-start);
System.out.println("Download: "+ava+" byte(s)"+" avg speed: "+speed+" (kb/s)");
}
bout.flush();
bout.close();
System.out.println("Done. size:"+ava+" byte(s)");
}
public static void main(String[] args) throws Exception {
URLReader.readAndSave(
"http://51hr.28tel.com.tw/UploadFile/Record/20090531114140.mp3",
"d:/双人舞.mp3");
}
}
======================================================
输出显示:
Starting.
Download: 8192 byte(s) avg speed: 6 (kb/s)
Download: 8385 byte(s) avg speed: 6 (kb/s)
Download: 16577 byte(s) avg speed: 11 (kb/s)
Download: 17025 byte(s) avg speed: 11 (kb/s)
Download: 25217 byte(s) avg speed: 15 (kb/s)
Download: 25665 byte(s) avg speed: 16 (kb/s)
Download: 33857 byte(s) avg speed: 19 (kb/s)
Download: 34305 byte(s) avg speed: 19 (kb/s)