65.9K
CodeProject 正在变化。 阅读更多。
Home

CMP3Info - 用于检索 MP3 文件信息的实现

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.92/5 (13投票s)

2002年4月17日

1分钟阅读

viewsIcon

249504

downloadIcon

6080

CMP3Info 是一个类, 使应用程序能够轻松访问 MP3 的信息(不是其实际数据)以及其 ID3 v1 标签

Example Screenshot

引言

你是否想编写一个程序来整理你的 MP3 文件,或者只是想在现有的应用程序中实现一个查看 MP3 文件详细信息的功能?如果是这样,那么 CMP3Info 类就是为你准备的。它提供了一种简单的方法来访问 MP3 的 ID3 标签(艺术家、标题、专辑等),以及关于 MP3 数据本身的几个细节——歌曲的长度、MPEG 编码类型、比特率、采样率、声道模式等。简单来说,你可以通过 CMP3Info 类提供的直观接口,检索到关于 MP3 文件所需的所有信息,除了 MP3 数据本身… :)

下面是从头文件中摘录的一部分,描述了类的主要功能

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);

正如你所看到的,这个类非常简单,而且体积很小。

注释

  • 尚未实现 Unicode 版本
  • 检索 MP3 帧信息的算法主要来自 MPEG 音频帧头
  • 并非所有类型的 MP3 文件都经过了彻底的测试
  • 自行使用,我不对任何损害负责

历史

  • 2002 年 6 月 12 日 - 更新演示程序,包含缺失的 .rc 文件

许可证

本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。

作者可能使用的许可证列表可以在此处找到。

© . All rights reserved.