Mega Code Archive

 
Categories / Delphi / Files
 

ID3 tags and MPEG headers information of MP3 files

Title: ID3 tags and MPEG headers information of MP3 files Question: How to extract ID3 tags and MPEG frame headers information from MP3 files Answer: Suppose You want to place list of titles and durations of all Your mp3 files contained in selected folder. Place at form TEdit for folder name and TListBox for result and use ScanMP3Folder (Edit1.Text, ListBox1.Items); implementation of ScanMP3Folder (You need TAudioInfo component - see component URL above, and TDirectoryScanner): procedure ScanMP3Folder (const AFolder : string; AMP3List : TStrings); var ds : TDirectoryScanner; a : TAudioInfo; Descr : string; i : integer; begin ds := TDirectoryScanner.Create; a := TAudioInfo.Create; try ds.Recursive := True; ds.RegExprMask := '\.mp[23]'; ds.BuildFileList (AFolder); for i := 0 to ds.Count - 1 do begin a.LoadFromFile (ds.Item [i].Name); if a.ID3.Ok then Descr := a.ID3.Artist + ' - ' + a.ID3.Title else Descr := ExtractFileName (ds.Item [i].Name); Descr := Descr + Format (' (%d sec)', [a.MpegDuration div 1000]); AMP3List.Add (Descr); end; finally begin a.Free; ds.Free; end; end; end;