Click here to Skip to main content
Licence 
First Posted 16 Apr 2002
Views 196,875
Bookmarked 70 times

CMP3Info - implementation for retrieving information about MP3 files

By | 11 Jun 2002 | Article
CMP3Info is a class which makes it simple for an application to gain easy access to an MP3's information (not its actual data) and its ID3 v1 tag

Example Screenshot

Introduction

Ever wanted to make a program to organize your MP3's, or just wanted to implement a feature in your existing application for viewing details about an MP3 file? If so, then the CMP3Info class is for you. It provides a simple method of accessing an MP3's ID3 tag (artist, title, album...) as well as several details concerning the MP3 data itself--the length of the song, the MPEG encoding type, bit rate, sample rate, channel mode, etc. Simply put, you can retrieve all the information you need about an MP3 file, except for the MP3 data itself... :), by using the intuitive interface provided by the CMP3Info class.

An excerpt from the header is shown below, describing the main functions of the class

CMP3Info(CString strFile = "");   // constructor, calls Open if 
virtual ~CMP3Info();              //    strFile is not ""

// operations
BOOL Open(CString strFile);	      // opens a file

// writes or clears the ID3v1 tag to (the/a) file
BOOL WriteID3V1(CString strDestFile, BOOL bClear...);	

void Clear();

void SetArtist(CString strArtist);    // self-explanatory, eh?
void SetTitle(CString strTitle);
void SetAlbum(CString strAlbum);
void SetComment(CString strComment);
void SetYear(CString strYear);
void SetTrack(int nTrack);

// see the global array in MP3Info.h for a list of genre
void SetGenreIndex(int nGenre); 

// attributes
// get the name of the file that was Open'd
CString GetFileName() const; 

// retrieve a bitmask of valid parts of the MP3 (frames/ID3 tag)
DWORD GetValidity() const;	  

CString GetArtist() const;
CString GetTitle() const;
CString GetAlbum() const;
CString GetComment() const;
CString GetYear() const;
int GetTrack() const;
int GetGenreIndex() const;

UINT GetNumFrames() const;
UINT GetLength() const;

// see the enumerations for more info
ENMPEGVER GetMPEGVersion() const; 

int GetMPEGLayer() const;
BOOL HasCRC() const;
int GetBitRate() const;
int GetSampleRate() const;
ENCHANNELMODE GetChannelMode() const;
ENEMPHASIS GetEmphasis() const;
BOOL IsCopyrighted() const;
BOOL IsOriginal() const;

// functions
// get string for a genre index in the array
static CString GetGenreString(int nIndex);

// create a string 'mm:ss' from the length
static CString GetLengthString(int nSeconds);

As you can see, the class is pretty simple, and is rather small.

Notes:

  • A Unicode version hasn't yet been implemented
  • The algorithm for retrieving the MP3 frame information is mostly taken from: MPEG Audio Frame Header
  • NOT ALL TYPES OF MP3 FILES HAVE BEEN THOROUGHLY TESTED
  • USE AT YOUR OWN RISK, I AM NOT LIABLE FOR DAMAGES

History

12 June 2002 - updated demo to include missing .rc file.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Roman Nurik

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow can i add a new field? Pinmemberk1488_sk8erboy2:18 14 Jul '08  
Generalusing on eVC++ [modified] Pinmemberkimhoontae19:36 15 Nov '07  
GeneralRe: using on eVC++ PinmemberRoman Nurik22:03 15 Nov '07  
GeneralInsert message digest in id3 tag PinsussAnonymous23:54 4 Feb '04  
GeneralRe: Insert message digest in id3 tag PinmemberRoman Nurik22:04 15 Nov '07  
QuestionHow to judge Bit Rate is constant or variable? PinmemberLinusWu20:53 12 Nov '03  
Generalsorry, about ID3V2 PinmemberRoman Nurik11:50 31 Jan '03  
GeneralError in de demo project and PinmemberBoscoW23:44 30 Jan '03  
GeneralRe: Error in de demo project and PinmemberRoman Nurik11:45 31 Jan '03  
GeneralRe: Error in de demo project and PinmemberEdwina3:55 25 Apr '03  
GeneralRe: Error in de demo project and PinmemberRoman Nurik6:07 25 Apr '03  
GeneralRe: Error in de demo project and Pinmemberedwina12:57 25 Apr '03  
GeneralRe: Error in de demo project and Pinmemberlucy3:26 4 May '04  
GeneralRe: Error in de demo project and Pinmemberwangxiaosmile3:19 31 Aug '06  
QuestionBug in BitRate matrix? Pinmemberpci18:55 3 Dec '02  
Questionhow to read ID3V2?? PinmemberNeverGrief10:22 30 Nov '02  
AnswerRe: how to read ID3V2?? PinmemberChristian Graus10:34 30 Nov '02  
GeneralRe: how to read ID3V2?? PinmemberNeverGrief12:27 30 Nov '02  
GeneralRe: how to read ID3V2?? PinmemberChristian Graus12:40 30 Nov '02  
GeneralRe: how to read ID3V2?? PinmemberNeverGrief12:48 30 Nov '02  
GeneralRe: how to read ID3V2?? PinmemberNeverGrief12:50 30 Nov '02  
GeneralRe: how to read ID3V2?? PinmemberChristian Graus13:06 30 Nov '02  
GeneralRe: how to read ID3V2?? PinsussAnonymous10:46 4 Dec '02  
AnswerRe: how to read ID3V2?? Pinmemberwhizer2:04 31 May '03  
GeneralRe: test Pinsuss20:44 18 Jul '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 12 Jun 2002
Article Copyright 2002 by Roman Nurik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid