累是挺累的,不過還是感覺很有激情!
寫這個讀MP3文件ID3V1的一點信息的,感覺不錯!
最近在用 Swing 寫一個MP3文件根據標簽信息重命名的程序,這么一聽的話感覺好像不是很難,但實際過程中卻遇到了很多問題,都有待于我一個一個去解決!
這次在尋找幫助時有一個犯了個很大的毛病就是沒有把一些好的文章存或者是鏈接下來。
別的先不說的,先把讀MP3文件頭部信息的程序貼出來:

/**//**
* Created on 2005-8-6 5:10:29
* @author 糊涂鬼
*/

public class ReadMp3ID3v1Info
{
private static final int TAG_SIZE = 128;
private static final int TITLE_SIZE = 30;
private static final int ARTIST_SIZE = 30;
private static final int ALBUM_SIZE = 30;
private static final int YEAR_SIZE = 4;
private static final int COMMENT_SIZE = 29;
private static final int TRACK_LOCATION = 126;
private static final int GENRE_LOCATION = 127;
private static final int MAX_GENRE = 255;
private static final int MAX_TRACK = 255;
private static final String ENC_TYPE = "Cp437";
private static final String TAG_START = "TAG";

public static void main(String[] args)
{

try
{
File mp3 = new File("F:/音樂/MP3/英文女歌手/Madonna - Music.mp3");
RandomAccessFile raf = new RandomAccessFile( mp3, "r" );
raf.seek(raf.length() - TAG_SIZE);
byte[] buf = new byte[TAG_SIZE];
raf.read(buf, 0, TAG_SIZE);
String tag = new String(buf, 0, TAG_SIZE, "Cp437");
int start = TAG_START.length();
System.out.println("文件名: " + mp3.getName());
System.out.println("標題 : " + tag.substring(start, start += TITLE_SIZE).trim());
System.out.println("藝術家: " + tag.substring(start, start += ARTIST_SIZE).trim());
raf.close();
System.out.println("====================================");

File mp32 = new File("F:/音樂/MP3/英文組合/blue - you make me wanna.mp3");
raf = new RandomAccessFile( mp32, "r" );
raf.seek(raf.length() - 128);
raf.read(buf, 0, 128);
tag = new String(buf, 0, 128, "Cp437");
start = TAG_START.length();
System.out.println("文件名: " + mp32.getName());
System.out.println("標題 : " + tag.substring(start, start += 30).trim());
System.out.println("藝術家: " + tag.substring(start, start += 30).trim());
raf.close();

} catch (Exception e)
{
}
}
}
運行的結果是:
文件名: Madonna - Music.mp3
標題 : Music
藝術家: Madonna
====================================
文件名: blue - you make me wanna.mp3
標題 : U Make Me Wanna
藝術家: Blue