//目的:列出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);
}
}
public class MainMP3
{
static void Main(string[] args)
{
if (args.Length == 1)
{
MP3Info mp3 = new MP3Info(args[0]);
bool f = mp3.readMP3Info();
if (f)
{
mp3.printMP3Info();
}
else
{
System.Console.WriteLine("该MP3没有标注");
}
}
else
{
System.Console.WriteLine("参数不正确,只能跟一个参数");
}
}
}
}
本文地址:http://com.8s8s.com/it/it43431.htm