BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can I read the MP3 tags

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia
View previous topic :: View next topic  
Author Message
dpap
Guest





PostPosted: Fri Aug 01, 2003 6:40 pm    Post subject: How can I read the MP3 tags Reply with quote



Hi,
I want to read the tags of a MP3 file (Title, artist bame etc) but I don't
know the file structure.
Can somebody help me ?

thanks in advance


Back to top
Nils Haeck
Guest





PostPosted: Tue Aug 12, 2003 7:47 pm    Post subject: Re: How can I read the MP3 tags Reply with quote



Hi there, here's a code snippet from an ID3 tag reader I wrote as part of my
file viewer.

//
// TID3Decode
//

type

TId3Tag = packed record
Tag: array[0..2] of char;
Title,
Artist,
Album: array[0..29] of char;
Year: array[0..3] of char;
Comment: array[0..29] of char;
GenreId: byte;
end;

const

Mp3Genre: array[0..79] 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', 'AlternRock', 'Bass', 'Soul', '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 American', 'Cabaret', 'New Wave', 'Psychadelic',
'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal', 'Acid Punk',
'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll',
'Hard Rock');

class function TID3Decode.IsValidSection(Stream: TStream): boolean;
var
MP3: word;
Tag: array[0..2] of char;
begin
Result := False;
Stream.Seek(0, soFromBeginning);
if Stream.Size >= 2 then begin
Stream.Read(MP3, 2);
MP3 := swap(MP3);
// Check the framesync (11 bits set)
if (MP3 and $FFE0) = $FFE0 then begin
// Check TAG
Stream.Seek(-128, soFromEnd);
Stream.Read(Tag, 3);
if Tag = 'TAG' then
Result := True;
end;
end;
end;

// Read the MP3 Id3 tag, add a XML tag with <ID3> if present
procedure TID3Decode.TagToXML(Stream: TStream; XML: TXMLObject);
var
Id3Tag: TId3Tag;
Genre: string;
begin
Stream.Seek(-128, soFromEnd);
Stream.Read(Id3Tag, SizeOf(Id3tag));
if (Id3Tag.Tag = 'TAG') and assigned(XML) then with ID3Tag do begin
XML.ChildAdd('Title', trim(Title));
XML.ChildAdd('Artist', trim(Artist));
XML.ChildAdd('Album', trim(Album));
XML.ChildAdd('Year', trim(Year));
XML.ChildAdd('Comment', trim(Comment));
Genre := 'Unknown';
if GenreId <= 79 then Genre := Mp3Genre[GenreID];
XML.ChildAdd('Genre', Genre);
end;
end;

Kind regards,

Nils Haeck
www.simdesign.nl


"dpap"
Quote:
Hi,
I want to read the tags of a MP3 file (Title, artist bame etc) but I don't
know the file structure.
Can somebody help me ?

thanks in advance





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.