严黎斌<br>unit ID3Kernel;<br><br>interface<br><br>type<br> Tid3v1= record<br> Tag: array[0..2] of char; //00..02 , ='TAG'<br> Title:array[0..$1d] of char; //03..20<br> Artist:array[0..$1d] of char; //21..3e<br> Album:array[0..$1d] of char; //3f..5c<br> Year:array[0..3] of char; //5d..60<br> Comment:array[0..$1c] of char; //61..7d<br> Track:byte; //7e<br> Genre:byte; //7f<br> end;<br><br>function ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;<br>function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;<br>function DeleteID3v1(strFile:string):integer;<br><br>implementation<br><br>function ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;<br>var<br> f1:file of byte;<br> bytAll: array [0..$7f] of byte;<br> i: integer;<br>begin<br> result:=1;<br> if strFile='' then exit;<br> AssignFile(f1,strFile);<br> FileMode:=0;<br> Reset(f1);<br> if FileSize(f1)<=$80 then exit;<br> Seek(f1, FileSize(f1)-$80);<br> for i:=0 to $7f do Read(f1,bytAll);<br> if (bytAll[0]<>ord('T')) and (bytAll[1]<>ord('A'))<br> and (bytAll[2]<>ord('G')) then exit; // no 'TAG' found<br> Move(bytAll,pid3v1,$80);<br> CloseFile(f1);<br> result:=0;<br>end;<br><br>function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;<br>var<br> f1:file of byte;<br> bytAll: array [0..$7f] of byte;<br> i: integer;<br>begin<br> result:=1;<br> AssignFile(f1,strFile);<br> FileMode:=2;<br> Reset(f1);<br> if FileSize(f1)<=$80 then exit;<br> Seek(f1, FileSize(f1)-$80);<br> for i:=0 to $2 do Read(f1,bytAll); // test if 'TAG' exists<br> if (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))<br> and (bytAll[2]=ord('G'))<br> then Seek(f1,FileSize(f1)-$80)<br> else Seek(f1,FileSize(f1));<br> Move(pid3v1,bytAll,$80);<br> for i:=0 to $7f do Write(f1,bytAll);<br> CloseFile(f1);<br> result:=0;<br>end;<br><br>function DeleteID3v1(strFile:string):integer;<br>var<br> f1:file of byte;<br> bytAll: array [0..$7f] of byte;<br> i: integer;<br>begin<br> Result:=1;<br> AssignFile(f1,strFile);<br> FileMode:=2;<br> Reset(f1);<br> if FileSize(f1)<=$80 then exit;<br> Seek(f1, FileSize(f1)-$80);<br> for i:=0 to $2 do Read(f1,bytAll); // test if 'TAG' exists<br> if (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))<br> and (bytAll[2]=ord('G'))<br> then begin<br> Seek(f1,FileSize(f1)-$80);<br> Truncate(f1)<br> end;<br> CloseFile(f1);<br> Result:=0;<br>end;<br><br>end.<br>