ID3介绍:

ID3,一般是位于一个mp3文件的开头或末尾的若干字节内,附加了关于该mp3的歌手,标题,专辑名称,年代,风格等信息,该信息就被称为ID3信息,ID3信息分为两个版本,v1和v2版。  

  获取歌曲的ID3信息,我使用的插件是Do Anything With ID3 。

主要代码:

using ID3;
using ID3.ID3v2Frames.BinaryFrames; namespace Testid3
{
class Program
{
//参考:
//Do Anything With ID3 - 赤色火焰 - 博客园 http://www.cnblogs.com/mgod/archive/2009/01/19/1377995.html //id3v2.3.0 - ID3.org http://id3.org/id3v2.3.0#sec4.1 //Do Anything With ID3 - CodeProject http://www.codeproject.com/Articles/17890/Do-Anything-With-ID static void Main(string[] args)
{
string file = @"E:\abcdef/123.mp3";
//http://www.cnblogs.com/babycool
ID3Info Data = new ID3Info(file, true);
var id31 = Data.ID3v1Info;
var id32 = Data.ID3v2Info;
//判断是否有id3v1
bool isid31 = id31.HaveTag;
//判断是否有id3v2
bool isid32 = id32.HaveTag; StringBuilder sbuilder = new StringBuilder(); if (isid31)
{
sbuilder.AppendLine("--------------id31---------");
sbuilder.AppendLine(string.Format("Title : {0}", id31.Title)); sbuilder.AppendLine(string.Format("artist : {0}", id31.Artist)); sbuilder.AppendLine(string.Format("album : {0}", id31.Album));
sbuilder.AppendLine(string.Format("genre : {0}", id31.Genre)); } if (isid32)
{
sbuilder.AppendLine("--------------id32---------");
//if (id32.VersionInfo.Minor != 3 && id32.VersionInfo.Minor != 4)
//{ //} //id3v2 版本
sbuilder.AppendLine(string.Format("version: {0}",id32.VersionInfo.ToString()));
//TIT2 标题/ Songname /内容描述
sbuilder.AppendLine(string.Format("Title:{0}", id32.GetTextFrame("TIT2")));
//TPE1 主艺术家
sbuilder.AppendLine(string.Format("Artist:{0}", id32.GetTextFrame("TPE1")));
//TALB 'Album/Movie/Show title 专辑
sbuilder.AppendLine(string.Format("Album:{0}", id32.GetTextFrame("TALB")));
//类型
sbuilder.AppendLine(string.Format("Genre:{0}", id32.GetTextFrame("TCON")));
//音轨
sbuilder.AppendLine(string.Format("Tracl:{0}", id32.GetTextFrame("TRCK")));
//时长
sbuilder.AppendLine(string.Format("时长:{0}", id32.GetTextFrame("TIME")));
sbuilder.AppendLine(string.Format("大小:{0}", id32.GetTextFrame("TLEN"))); } Console.WriteLine(sbuilder.ToString()); Console.ReadKey(); }
}
}

结果:

[开发笔记]-获取歌曲ID3信息-LMLPHP

转载请注明出处。

05-04 11:28