Click here to Skip to main content
12,356,052 members (72,542 online)
Click here to Skip to main content
Add your own
alternative version

Stats

207.7K views
11.2K downloads
118 bookmarked
Posted

MP3FileInfo - Extract Header and ID3 Tags of an MP3 File

, 30 May 2003
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

whizer
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questionmove to qt creator project ? Pin
atx2376-Jun-14 3:21
memberatx2376-Jun-14 3:21 
GeneralMy vote of 5 Pin
james_chyn10-Oct-11 17:53
memberjames_chyn10-Oct-11 17:53 
GeneralMy vote of 5 Pin
paul116728-Sep-11 21:54
memberpaul116728-Sep-11 21:54 
Generalbug,occur one bug. Pin
zhang_19855-Aug-09 22:08
memberzhang_19855-Aug-09 22:08 
Generalincorrect duration and bitrate Pin
autotesting@mail.ru11-Jan-09 10:17
memberautotesting@mail.ru11-Jan-09 10:17 
Generalusing to eVC++ Pin
kimhoontae15-Nov-07 21:01
memberkimhoontae15-Nov-07 21:01 
GeneralRe: using to eVC++ Pin
whizer16-Nov-07 0:58
memberwhizer16-Nov-07 0:58 
GeneralClumsy program Pin
Drexel Gal28-Jul-07 18:44
memberDrexel Gal28-Jul-07 18:44 
GeneralAnother linkerror Pin
sonocln14-Jun-07 10:54
membersonocln14-Jun-07 10:54 
GeneralRe: Another linkerror Pin
whizer14-Jun-07 11:38
memberwhizer14-Jun-07 11:38 
GeneralForeign languaga Pin
HYCKen27-Jan-07 4:23
memberHYCKen27-Jan-07 4:23 
AnswerRe: Foreign languaga Pin
whizer27-Jan-07 5:12
memberwhizer27-Jan-07 5:12 
Generalstatic lib...how? [modified] Pin
aullidolunar11-Nov-06 14:47
memberaullidolunar11-Nov-06 14:47 
GeneralRe: static lib...how? Pin
whizer12-Nov-06 11:20
memberwhizer12-Nov-06 11:20 
GeneralError Compiling Pin
Daniel Ahdoot16-Aug-06 11:53
memberDaniel Ahdoot16-Aug-06 11:53 
AnswerRe: Error Compiling [modified] Pin
whizer16-Aug-06 22:47
memberwhizer16-Aug-06 22:47 
Generalerror szComment Pin
tenstars26-Feb-06 21:09
membertenstars26-Feb-06 21:09 
GeneralLinkers error Pin
rayman228-Dec-05 11:39
memberrayman228-Dec-05 11:39 
GeneralRe: Linkers error Pin
whizer28-Dec-05 23:09
memberwhizer28-Dec-05 23:09 
GeneralRe: Linkers error Pin
rayman229-Dec-05 1:25
memberrayman229-Dec-05 1:25 
GeneralRe: Linkers error Pin
WhiteWolf[SLO]29-Dec-05 14:00
memberWhiteWolf[SLO]29-Dec-05 14:00 
GeneralBUG FIX! Pin
win32_coder7-Sep-05 1:43
memberwin32_coder7-Sep-05 1:43 
QuestionGot the DLL? Pin
roopeshsheth7-May-05 7:19
memberroopeshsheth7-May-05 7:19 
AnswerRe: Got the DLL? Pin
whizer7-May-05 9:00
memberwhizer7-May-05 9:00 
QuestionCompatibility with C++ Builder? Pin
[CeeFour]1-Feb-05 8:08
member[CeeFour]1-Feb-05 8:08 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 31 May 2003
Article Copyright 2003 by whizer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid