日期:2014-05-20  浏览次数:20639 次

java如何解析mp3文件?
java如何解析mp3文件?
例如:讀取藝術家、專輯、歌曲長度、比特率......

------解决方案--------------------
关注
------解决方案--------------------
好象jmf已经支持mp3了,去sun那边找找文档吧
------解决方案--------------------
mark..
------解决方案--------------------
mp3文件尾部保存ID3V1 信息
/**
* TRAILER
at end of file - 128 bytes
offset type len name
--------------------------------------------
0 char 3 "TAG "
3 char 30 title
33 char 30 artist
63 char 30 album
93 char 4 year
97 char 30 comments
127 byte 1 genre
--------------------------------------------

*/
public static void readMp3ID3V1(String fp) throws Exception{
byte[] buf = new byte[1024];
File file = new File(fp);

FileInputStream fis = new FileInputStream(file);
/*---读取MP3文件尾部信息,并显示----*/
long size = file.length();
fis.skip(size-128);
//标志位TAG 3 byte
fis.read(buf,0,3);
String tag = new String(buf,0,3);
System.out.println( "ID3V1: "+tag);
//歌曲名称 30 byte
fis.read(buf,0,30);

int len = seekNz(buf,30);
String name = new String(buf,0,len);
System.out.println( "song name: "+name);
//歌手名称 30 byte
fis.read(buf,0,30);
len = seekNz(buf,30);
name = new String(buf,0,len);
System.out.println( "singer name: "+name);
//专辑名称 30 byte
fis.read(buf,0,30);
len = seekNz(buf,30);
name = new String(buf,0,len);
System.out.println( "album name: "+name);
//年代 4 byte
fis.read(buf,0,4);
name = new String(buf,0,4);
System.out.println( "year : "+name);
//comment 30 byte
fis.read(buf,0,30);
len = seekNz(buf,30);
name = new String(buf,0,len);
System.out.println( "comment: "+name);
//genre 1 byte
fis.read(buf,0,1);
// name = new String(buf,0,30);
System.out.println( "Genre: "+buf[0]);
fis.close();

}
------解决方案--------------------
mark
------解决方案--------------------
觉得是用流的方式读取!但是不知道mp3的信息是怎么存的!
------解决方案--------------------
学习!
------解决方案--------------------
学习~~~~关注中