type //128字节的ID3v1结构
ID3Struct = packed record
fID: Array [0..2 ] of Char;
fTitle: Array [0..29] of Char;
fArtist: Array [0..29] of Char;
fAlbum: Array [0..29] of Char;
fYear: Array [0..3 ] of Char;
fComment: Array [0..29] of Char;
fGenre: Byte;
end;
private
FStream:TFileStream;
Tag,Tag2: ID3Struct;
FVersion: Byte;
public
Title, Artist, Album, Year, Comment:string;
Genre, Track: byte;
GenreStr:string;//流派对应字符串
Filename:string;//文件名
function ReadTag:boolean;
begin
//读MP3文件息信
Result:=false;
try
FStream:=TFileStream.Create(Filename,fmOpenRead);
FStream.Seek(-128,soFromEnd);
FStream.ReadBuffer(Tag,128);//读取TAG
if StrLComp(Tag.fID,'TAG',3)=0 then
with Tagdo
begin
FVersion := GetTagVersion(Tag);
Title:=Trim(Copy(FTitle, 1, SizeOf(FTitle)));
Artist:=Trim(Copy(FArtist, 1, SizeOf(FArtist)));
Album:=Trim(Copy(FAlbum, 1, SizeOf(FAlbum)));
Year:=Trim(Copy(FYear, 1, SizeOf(FAlbum)));
Comment:=Trim(Copy(FComment, 1, SizeOf(FComment)));
if FVersion = VERSION_1_0 then
Track := 0
else
Track := Ord(FComment[29]);
Genre:=FGenre;
result:=true;
end;
finally
Fstream.Free;
end;
end;