Article View: borland.public.cppbuilder.multimedia
Article #988Re: Mp3 and video files
From: ScOe
Date: Fri, 05 Apr 2002 10:36
Date: Fri, 05 Apr 2002 10:36
166 lines
6698 bytes
6698 bytes
"Umut Besler" <umutbesler@yahoo.com> wrote in message
news:3ca5dccd_2@dnews...
> How can i get time, bitrate, IDTags of mp3 files
> and how can i get time, resolution and codec avi files
>
> thanks
>
>
I'm usign following code for IDTag extracting where ID->Edit->Text is Edit
field where i show information
# define SHOWERRORANDQUIT Abort();
void __fastcall TMainForm::Mp3IDClick(TObject *Sender)
{
HANDLE handle; //handle to the mp3 file
SECURITY_ATTRIBUTES security_attributes; //need it to open a file
HGLOBAL hFileBuffer; //memory buffer
DWORD dwBytesRead; //bytes read
ID3 tag; //the ID3 information
hFileBuffer = GlobalAlloc(GPTR, // object allocation attributes
128 // number of bytes to allocate
);
if(!hFileBuffer)
SHOWERRORANDQUIT;
//fill in the security struct
security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
security_attributes.lpSecurityDescriptor = NULL;
security_attributes.bInheritHandle = FALSE;
handle = CreateFile(FileListBox1->FileName.c_str(), //the name
GENERIC_READ, //we want to read
FILE_SHARE_READ, //others can read it at the same
time
&security_attributes, //security
OPEN_EXISTING, //the file exists
FILE_ATTRIBUTE_NORMAL, //normal attributes
NULL //no template
);
if(!handle)
SHOWERRORANDQUIT;
if(SetFilePointer(handle, //handle of file
-128, //number of bytes to move file pointer
NULL, //address of high-order word of distance to
move
FILE_END //how to move
) == 0xFFFFFFFF)
{
CloseHandle(handle);
SHOWERRORANDQUIT;
}
if(!ReadFile(handle, //handle of file to read
GlobalLock(hFileBuffer), //address of buffer that receives
data
128, //number of bytes to read
&dwBytesRead, //address of number of bytes read
NULL //address of structure for data
))
{
CloseHandle(handle);
SHOWERRORANDQUIT;
}
CloseHandle(handle);
//did we read 128 bytes?
if(dwBytesRead != 128)
SHOWERRORANDQUIT;
//init the ID3 information
if(!tag.Init(hFileBuffer))
SHOWERRORANDQUIT;
ID->Edit1->Clear();
ID->Edit2->Clear();
ID->Edit3->Clear();
ID->Edit4->Clear();
ID->Edit5->Clear();
ID->Edit5->Clear();
AnsiString Title = tag.ReturnTitle();
AnsiString Artist = tag.ReturnArtist();
AnsiString Album = tag.ReturnAlbum();
AnsiString Comments = tag.ReturnComments();
int k = Title.Pos(" ");
int j = Artist.Pos(" ");
int l = Album.Pos(" ");
int m = Comments.Pos(" ");
Title.Delete(k,30);
Artist.Delete(j,30);
Album.Delete(l,30);
Comments.Delete(m,30);
ID->Edit1->Text = Title;
ID->Edit2->Text = Artist;
ID->Edit3->Text = Album;
ID->Edit4->Text = tag.ReturnYear();
ID->Edit5->Text = Comments;
ID->Edit6->Text = tag.ReturnGenre();
}
BOOL ID3::Init(HGLOBAL hglobal)
{
BYTE *lpByte = (BYTE*)GlobalLock(hglobal);
const char genres[81][20] = {{"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"},{"Unknown"}};
if(!((char)lpByte[0] == 'T' && (char)lpByte[1] == 'A' &&
(char)lpByte[2] == 'G'))
return FALSE;
memcpy((void*)title,(void*)&lpByte[3],(size_t)30);
memcpy((void*)artist,(void*)&lpByte[33],(size_t)30);
memcpy((void*)album,(void*)&lpByte[63],(size_t)30);
memcpy((void*)year,(void*)&lpByte[93],(size_t)4);
memcpy((void*)comments,(void*)&lpByte[97],(size_t)30);
if(lpByte[127] >= 0 && lpByte[127] < 80)
lstrcpy(genre,genres[lpByte[127]]);
//the genre is "Unknown"
else
lstrcpy(genre,genres[80]);
title[30] = '\0';
artist[30] = '\0';
album[30] = '\0';
year[4] = '\0';
comments[30] = '\0';
return TRUE;
}
Hope this helped !!
Greet
Technical Details
Message-ID:
<3cad7e2c_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3ca5dccd_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d0fc,a9e6e678a19ec620 X-Google-Attributes: gid10d0fc,public X-Google-ArrivalTime: 2002-04-05 02:40:12 PST From: "ScOe" <sven.savic@zg.hinet.hr> Newsgroups: borland.public.cppbuilder.multimedia References: <3ca5dccd_2@dnews> Subject: Re: Mp3 and video files Date: Fri, 5 Apr 2002 12:36:26 +0200 Lines: 168 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 195.29.133.76 Message-ID: <3cad7e2c_2@dnews> X-Trace: dnews 1018002988 195.29.133.76 (5 Apr 2002 02:36:28 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!dnews