static void Main(string[] args)
{
byte[] b = new byte[128];
string sTitle;
string sSinger;
string sAlbum;
string sYear;
string sComm;
FileStream fs = new FileStream(@"d:/mp3.mp3", FileMode.Open);
fs.Seek(-128, SeekOrigin.End);
fs.Read(b, 0, 128);
bool isSet=false;
String sFlag = System.Text.Encoding.Default.GetString(b, 0, 3);
if (sFlag.CompareTo("TAG")==0)
{
System.Console.WriteLine ("Tag is setted!");
isSet=true;
}
if (isSet)
{
//get title of song;
sTitle = System.Text.Encoding.Default.GetString (b,3,30);
System.Console.WriteLine ("Title:" + sTitle);
//get singer;
sSinger = System.Text.Encoding.Default.GetString (b,33,30);
System.Console.WriteLine ("Singer:" + sSinger);
//get album;
sAlbum = System.Text.Encoding.Default.GetString (b,63,30);
System.Console.WriteLine ("Album:" + sAlbum);
//get Year of publish;
sYear= System.Text.Encoding.Default.GetString (b,93,4);
System.Console.WriteLine ("Year:" + sYear);
//get Comment;
sComm= System.Text.Encoding.Default.GetString (b,97,30);
System.Console.WriteLine ("Comment:" + sComm);
}
System.Console.WriteLine("Any key to exit!");
System.Console.Read();
}
获取文件的附加信息之MP3篇
最新推荐文章于 2024-08-30 15:35:58 发布
本文介绍了一段C#代码,该代码用于从MP3文件末尾的ID3v1标签中读取歌曲标题、歌手、专辑、年份及评论等信息。通过FileStream和Seek方法定位到文件末尾前128字节处,并检查是否存在“TAG”标志来判断是否有ID3v1标签。
5088

被折叠的 条评论
为什么被折叠?



