转.mp3 ID3标签信息    unit ID3Kernel;interfacetypeTid3v1= recordTag: array[0..2] of char; //00..02 , ='TAG'Title:array[0..$1d] of char; //03..20Artist:array[0..$1d] of char; //21..3eAlbum:array[0..$1d] of char; //3f..5cYear:array[0..3] of char; //5d..60Comment:array[0..$1c] of char; //61..7dTrack:byte; //7eGenre:byte; //7fend;function ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;function DeleteID3v1(strFile:string):integer;implementationfunction ReadID3v1(strFile:string;var pid3v1:Tid3v1):integer;varf1:file of byte;bytAll: array [0..$7f] of byte;i: integer;beginresult:=1;if strFile='' then exit;AssignFile(f1,strFile);FileMode:=0;Reset(f1);if FileSize(f1)<=$80 then exit;Seek(f1, FileSize(f1)-$80);for i:=0 to $7f do Read(f1,bytAll[i]);if (bytAll[0]<>ord('T')) and (bytAll[1]<>ord('A'))and (bytAll[2]<>ord('G')) then exit; // no 'TAG' foundMove(bytAll,pid3v1,$80);CloseFile(f1);result:=0;end;function WriteID3v1(strFile:string;var pid3v1:Tid3v1):integer;varf1:file of byte;bytAll: array [0..$7f] of byte;i: integer;beginresult:=1;AssignFile(f1,strFile);FileMode:=2;Reset(f1);if FileSize(f1)<=$80 then exit;Seek(f1, FileSize(f1)-$80);for i:=0 to $2 do Read(f1,bytAll[i]); // test if 'TAG' existsif (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))and (bytAll[2]=ord('G'))then Seek(f1,FileSize(f1)-$80)else Seek(f1,FileSize(f1));Move(pid3v1,bytAll,$80);for i:=0 to $7f do Write(f1,bytAll[i]);CloseFile(f1);result:=0;end;function DeleteID3v1(strFile:string):integer;varf1:file of byte;bytAll: array [0..$7f] of byte;i: integer;beginResult:=1;AssignFile(f1,strFile);FileMode:=2;Reset(f1);if FileSize(f1)<=$80 then exit;Seek(f1, FileSize(f1)-$80);for i:=0 to $2 do Read(f1,bytAll[i]); // test if 'TAG' existsif (bytAll[0]=ord('T')) and (bytAll[1]=ord('A'))and (bytAll[2]=ord('G'))then beginSeek(f1,FileSize(f1)-$80);Truncate(f1)end;CloseFile(f1);Result:=0;end;end.***********************************************{Byte 1-3 = ID 'TAG'Byte 4-33 = Titel / TitleByte 34-63 = ArtistByte 64-93 = AlbumByte 94-97 = Jahr / YearByte 98-127 = Kommentar / CommentByte 128 = Genre} typeTID3Tag = recordID: string[3];Titel: string[30];Artist: string[30];Album: string[30];Year: string[4];Comment: string[30];Genre: Byte;end;constGenres : array[0..146] of string =('Blues','Classic Rock','Country','Dance','Disco','Funk','Grunge','Hip- Hop','Jazz','Metal','New Age','Oldies','Other','Pop','R&B','Rap','Reggae','Rock','Techno','Industrial','Alternative','Ska','Death Metal','Pranks','Soundtrack','Euro-Techno','Ambient','Trip-Hop','Vocal','Jazz+Funk','Fusion','Trance','Classical','Instrumental','Acid','House','Game','Sound Clip','Gospel','Noise','Alternative Rock','Bass','Punk','Space','Meditative','Instrumental Pop','Instrumental Rock','Ethnic','Gothic','Darkwave','Techno-Industrial','Electronic','Pop-Folk','Eurodance','Dream','Southern Rock','Comedy','Cult','Gangsta','Top 40','Christian Rap','Pop/Funk','Jungle','Native US','Cabaret','New Wave','Psychadelic','Rave','Showtunes','Trailer','Lo-Fi','Tribal','Acid Punk','Acid Jazz','Polka','Retro','Musical','Rock & Roll','Hard Rock','Folk','Folk-Rock','National Folk','Swing','Fast Fusion','Bebob','Latin','Revival','Celtic','Bluegrass','Avantgarde','Gothic Rock','Progressive Rock','Psychedelic Rock','Symphonic Rock','Slow Rock','Big Band','Chorus','Easy Listening','Acoustic','Humour','Speech','Chanson','Opera','Chamber Music','Sonata','Symphony','Booty Bass','Primus','Porn Groove','Satire','Slow Jam','Club','Tango','Samba','Folklore','Ballad','Power Ballad','Rhytmic Soul','Freestyle','Duet','Punk Rock','Drum Solo','Acapella','Euro-House','Dance Hall','Goa','Drum & Bass','Club-House','Hardcore','Terror','Indie','BritPop','Negerpunk','Polsk Punk','Beat','Christian Gangsta','Heavy Metal','Black Metal','Crossover','Contemporary C','Christian Rock','Merengue','Salsa','Thrash Metal','Anime','JPop','SynthPop'); varForm1: TForm1;implementation{$R *.dfm}function readID3Tag(FileName: string): TID3Tag;varFS: TFileStream;Buffer: array [1..128] of Char;beginFS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);tryFS.Seek(-128, soFromEnd);FS.Read(Buffer, 128);with Result dobeginID := Copy(Buffer, 1, 3);Titel := Copy(Buffer, 4, 30);Artist := Copy(Buffer, 34, 30);Album := Copy(Buffer, 64, 30);Year := Copy(Buffer, 94, 4);Comment := Copy(Buffer, 98, 30);Genre := Ord(Buffer[128]);end;finallyFS.Free;end;end;procedure TfrmMain.Button1Click(Sender: TObject);beginif OpenDialog1.Execute thenbeginwith readID3Tag(OpenDialog1.FileName) dobeginLlbID.Caption := 'ID: ' + ID;LlbTitel.Caption := 'Titel: ' + Titel;LlbArtist.Caption := 'Artist: ' + Artist;LlbAlbum.Caption := 'Album: ' + Album;LlbYear.Caption := 'Year: ' + Year;LlbComment.Caption := 'Comment: ' + Comment;if (Genre >= 0) and (Genre <=146) thenLlbGenre.Caption := 'Genre: ' + Genres[Genre]elseLlbGenre.Caption := 'N/A';end;end;end;

解决方案 »

  1.   

    我以前做过一个mp3播放器,留下email我给你寄过去阿。里面很全,拖拽播放,循环,列表,保存m3u,都有了。特别适合新手学习!先给你读取mp3信息的代码:
    procedure TForm1.FileListBox1Click(Sender: TObject);
    var mymp3:TID3Tag; mp3file:tfilestream;
    begin
    listbox1.Clear;
    mp3file:=tfilestream.Create(self.FileListBox1.FileName,fmOpenRead);
    try
        mp3file.position:=mp3file.size-128; // 跳到id3-tag
        mp3file.Read(mymp3,SizeOf(mymp3));
        listbox1.Items.Add('歌曲名称:'+mymp3.Title);
        listbox1.Items.Add('艺术家:'+mymp3.Artist);
         listbox1.Items.Add('专辑:'+mymp3.Album);
         listbox1.Items.Add('出版日期:'+mymp3.Year);
         listbox1.Items.Add('评论:'+mymp3.Comment);
         edit1.Text:= mymp3.Title;
    finally
    mp3file.Free;
     end;
    end;
    别忘了加上
    type 
    TID3Tag = packed record // 128 字节
       TAGID: array[0..2] of char; // 3 字节: 必须是TAG
       Title: array[0..29] of char; // 30 字节: 歌曲标题
       Artist: array[0..29] of char; // 30 字节: 歌曲的艺术家
       Album: array[0..29] of char; // 30 字节: 歌曲专辑
       Year: array[0..3] of char; // 4 字节: 出版年
       Comment: array[0..29] of char; // 30 字节: 评论
       Genre: byte; // 1 字节: 种类标识//放在 TForm1 = class(TForm)之前