Click here to Skip to main content
Licence 
First Posted 30 May 2003
Views 173,670
Bookmarked 115 times

MP3FileInfo - Extract Header and ID3 Tags of an MP3 File

By | 30 May 2003 | Article
MP3FileInfo is able to extract both ID3v1 and ID3v2 Tags of an MP3 File.

Introduction

In the need of structuring my MP3 collection, I wrote the class MP3FileInfo as a read-only wrapper for id3lib. id3lib is an open-source software library for manipulating ID3v1/v1.1 and ID3v2 tags. Since id3lib is a very powerful library, the API is also quite complex. That's why a wrapper class with a more interface is very useful.

How to use

MP3FileInfo uses a slightly different initialization concept. The constructor does nothing apart from initializing all member variables to zero/false. A call to Init() is needed in order to extract the actual data. But one can call Init() as often as wanted without any memory leak. All data is being freed before the data of the new file is extracted.

// create object (don't use it at this point)
MP3FileInfo obj;

// Initialize object with data
if(!obj.Init("some-file.mp3"))
 {
  // handle error ...
  // don't use object (except Init()) after this point
 }

// ... use MP3FileInfo ...

It is recommended to check MP3FileInfo::isOK() before doing any action.

Interface

After successfully calling Init(const char* cszFilename), the class provides the following public members:

File-specific

  • char* szFilename - Zero terminated Filename as supplied by Init(...)
  • int nFileSize - Size of the file in bytes
  • bool bHasV1Tag - Whether the file contains an ID3v1 tag
  • bool bHasV2Tag - Whether the file contains an ID3v2 tag
  • bool bHasLyrics - Whether the file contains Lyrics

Header-specific:

  • int nLength - Length of song in seconds
  • int nCbrBitRate - Bitrate in bits per second (is 0 if file uses variable bitrate)
  • int nVbrBitRate - Average bitrate in bits per second (is 0 if file uses constant bitrate)
  • int nBitRate - Bitrate in bits per second (if file uses constant bitrate, nCbrBitRate is used otherwise nVbrBitRate)
  • int nSampleRate - Sample rate of file in Hertz
  • char* szBitRate - Human readable string containing bitrate information, e.g. "160 kbit/s" or "147 kbit/s (VBR)"
  • char* szMpegLayer - MPEG layer information, e.g. "Layer III"
  • char* szMpegVersion - MPEG version information, e.g. "MPEG 1"
  • char* szChannelMode - Channel mode, e.g. "Stereo", "Single Channel"

ID3v1 Tag Elements (and up):

  • char* szArtist; - Artist of song
  • char* szTitle; - Song title
  • char* szAlbum; - Album
  • char* szComment; - Comment
  • char* szTrack; - Track description (may contain non-numeric characters)
  • char* szYear; - Year of publication/performance (may contain non-numeric characters)
  • char* szGenre; - Name of Genre
  • int nTrack; - Track number extracted of szTrack
  • int nYear; - Year of publication/performance extract of szYear

ID3v2-specific Tag Elements (only common):

  • char* szComposer; - Composer of song
  • char* szCopyright; - Copyright notices
  • char* szEncodedBy; - Encoded by, often used by audio converting programs like Exact Audio Copy
  • char* szOriginalArtist; - Original Artist, useful if the song is covered
  • char* szURL; - URL, e.g. Link to the homepage of an artist

Note: Most strings and numbers may be zero if a field isn't defined. The ID3v2-specific strings are only available if bHasV2Tag is true (should be obvious). All ID3v1-specific elements are superceded by the corresponding ID3v2 field if present and non-zero/non-empty.

History

  • May 31, 2003 - First Release 1.0.0

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

whizer

Web Developer

United Kingdom United Kingdom

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
GeneralMy vote of 5 Pinmemberjames_chyn17:53 10 Oct '11  
GeneralMy vote of 5 Pinmemberpaul116721:54 28 Sep '11  
Generalbug,occur one bug. Pinmemberzhang_198522:08 5 Aug '09  
Generalincorrect duration and bitrate Pinmemberautotesting@mail.ru10:17 11 Jan '09  
Generalusing to eVC++ Pinmemberkimhoontae21:01 15 Nov '07  
GeneralRe: using to eVC++ Pinmemberwhizer0:58 16 Nov '07  
GeneralClumsy program PinmemberDrexel Gal18:44 28 Jul '07  
GeneralAnother linkerror Pinmembersonocln10:54 14 Jun '07  
GeneralRe: Another linkerror Pinmemberwhizer11:38 14 Jun '07  
GeneralForeign languaga PinmemberHYCKen4:23 27 Jan '07  
AnswerRe: Foreign languaga Pinmemberwhizer5:12 27 Jan '07  
Generalstatic lib...how? [modified] Pinmemberaullidolunar14:47 11 Nov '06  
GeneralRe: static lib...how? Pinmemberwhizer11:20 12 Nov '06  
GeneralError Compiling PinmemberDaniel Ahdoot11:53 16 Aug '06  
AnswerRe: Error Compiling [modified] Pinmemberwhizer22:47 16 Aug '06  
Generalerror szComment Pinmembertenstars21:09 26 Feb '06  
GeneralLinkers error Pinmemberrayman211:39 28 Dec '05  
GeneralRe: Linkers error Pinmemberwhizer23:09 28 Dec '05  
GeneralRe: Linkers error Pinmemberrayman21:25 29 Dec '05  
GeneralRe: Linkers error PinmemberWhiteWolf[SLO]14:00 29 Dec '05  
GeneralBUG FIX! Pinmemberwin32_coder1:43 7 Sep '05  
QuestionGot the DLL? Pinmemberroopeshsheth7:19 7 May '05  
AnswerRe: Got the DLL? Pinmemberwhizer9:00 7 May '05  
QuestionCompatibility with C++ Builder? Pinmember[CeeFour]8:08 1 Feb '05  
AnswerRe: Compatibility with C++ Builder? Pinmemberwhizer8:39 1 Feb '05  

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
Web03 | 2.5.120517.1 | Last Updated 31 May 2003
Article Copyright 2003 by whizer
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid