//目的:列出MP3的一些標簽信息
//作者:李艷慶
using System;
using System.IO;
namespace mp3infons
{
class MP3Info
{
struct MP3InfoStruct
{
public string MP3Flag;
public string Title;
public string Singer;
public string Album;
public string Year;
public string Comment;
}
private string MP3File;
MP3InfoStruct mp3struct;
public MP3Info(string MP3Name)
{
MP3File = MP3Name;
mp3struct = new MP3InfoStruct();
}
public bool readMP3Info()
{
bool isSet=false;
byte[] b = new byte[128];
try
{
FileStream fs = new FileStream(MP3File, FileMode.Open);
fs.Seek(-128, SeekOrigin.End);
fs.Read(b, 0, 128);
mp3struct.MP3Flag = System.Text.Encoding.Default.GetString(b, 0, 3);
if (mp3struct.MP3Flag.CompareTo("TAG")==0)
{
//檢查是否設置了標簽
isSet=true;
mp3struct.Title = System.Text.Encoding.Default.GetString (b,3,30);
mp3struct.Singer = System.Text.Encoding.Default.GetString (b,33,30);
mp3struct.Album = System.Text.Encoding.Default.GetString (b,63,30);
mp3struct.Year = System.Text.Encoding.Default.GetString (b,93,4);
mp3struct.Comment = System.Text.Encoding.Default.GetString (b,97,30);
}
fs.Close();
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
return isSet;
}
public void printMP3Info()
{
System.Console.WriteLine("MP3附加信息:");
System.Console.WriteLine("-----------------------------");
System.Console.WriteLine("標 題: " + mp3struct.Title);
System.Console.WriteLine("歌 手: " + mp3struct.Singer);
System.Console.WriteLine("唱片集: " + mp3struct.Album);
System.Console.WriteLine("出版期: " + mp3struct.Year);
System.Console.WriteLine("備 注: " + mp3struct.Comment);
}
}