может не самый оптимальный способ (давно писал)но всеже:
| Код | type TTagRec = array [0..11] of string;
..............................................
Procedure GetMp3Tag(Filename:string;var tagrec:ttagrec;var tagbool:boolean); // TTagRec = array [0..11] of string; const MAXBytes = (High(integer) - $F) div sizeof(byte); type TByteArray = array[0..MAXBytes] of byte; PByteArray = ^TByteArray; Tconstmas = array [0..11,0..3] of byte; const ID3v1: array[0..2]of byte =(84,65,71); ID3v2: array[0..2]of byte =(73,68,51); EndID3:array[0..1]of byte =(255,251); Constlist:Tconstmas=( (84,69,78,67),(87,88,88,88),(84,67,79,80), (84,79,80,69),(84,67,79,77),(84,67,79,78), (84,82,67,75),(67,79,77,77),(84,89,69,82), (84,65,76,66),(84,80,69,49),(84,73,84,50)); {Encodedby,URL,Copyrigth, Origartist,Composer,Genre, Track,Comment,Year, Album,Artist,Title} var Buf : PByteArray; FileLength,FileHandle,i,j,k,nseek,lengthConst,SizeBuf: Integer; z:byte; bool:boolean; mas1:array [0..63] of byte; begin for i:=0 to 11 do tagrec[i]:=''; tagbool:=true; FileHandle := FileOpen(Filename,2);
//ID3v1 FileLength := FileSeek(FileHandle,0,2); FileSeek(FileHandle,filelength-128,0); FileRead(FileHandle,mas1,64); bool:=true; for i:=0 to 2 do if mas1[i]<>ID3v1[i] then bool:=false; if bool=true then begin for i:=0 to 29 do begin TagRec[11]:=tagrec[11]+chr(mas1[i+3]); //title TagRec[10]:=tagrec[10]+chr(mas1[i+33]); //artist end; end else begin // Проверка на ID3v2 SizeBuf:=3; GetMem(Buf, SizeBuf*sizeof(byte)); FileSeek(FileHandle,0,0); FileRead(FileHandle,Buf^,3); bool:=true; for i:=0 to 2 do if Buf^[i]<>ID3v2[i] then bool:=false; FreeMem(Buf, SizeBuf*sizeof(byte)); if bool=true then begin // поиск конкретного значения (сравнение с ConstList) for z:=10 to 11 do begin SizeBuf:=8; GetMem(Buf, SizeBuf*sizeof(byte)); nseek:=10; repeat FileSeek(FileHandle,nseek,0); FileRead(FileHandle,Buf^,8); bool:=true; for j:=0 to 3 do if buf^[j]<>constlist[z,j] then bool:=false; if bool=false then nseek:=nseek+10+(buf^[7]); until bool=true or((buf^[4]=255)and(buf^[5]=251)); lengthConst:=buf^[7]-1; FreeMem(Buf, SizeBuf*sizeof(byte)); // чтение записи SizeBuf:=lengthConst; GetMem(Buf,SizeBuf*sizeof(byte)); FileSeek(FileHandle,nseek+11,0); FileRead(FileHandle,Buf^,SizeBuf); for k:=0 to SizeBuf do TagRec[z]:=tagrec[z]+chr(buf^[k]); FreeMem(Buf, SizeBuf*sizeof(byte)); end; end else tagbool:=false; end; FileClose(FileHandle); end;
|
Урезанная правда до title и Artist |