C# 获取MP3信息

方法较于网上搜的方法要稍容易理解些,只例举了其中几个字段的获取方法

 

    struct Mp3Info
    {
        public string Title;  //歌曲名,30个字节     3-62 
        public string Artist; //歌手名,30个字节     33-62
        public string Album;  //专辑名,30个字节     63-92
        //public string Year;//年,4个字符     
        //public string Comment;//注释,28个字节      
        //public char reserved1;//保留位,一个字节        
        //public char reserved2;//保留位,一个字节        
        //public char reserved3;//保留位,一个字节  

        public Mp3Info(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            fs.Seek(-128, SeekOrigin.End);
            byte[] Info = new byte[128];
            int length = fs.Read(Info, 0, 128);
            fs.Close();

            Title = Encoding.Default.GetString(Info, 3, 30).Replace("\0", string.Empty);
            Artist = Encoding.Default.GetString(Info, 33, 30).Replace("\0", string.Empty);
            Album = Encoding.Default.GetString(Info, 63, 30).Replace("\0", string.Empty);
        }
    }

使用时

 

                Mp3Info mp3 = new Mp3Info("E:\\音乐\\down\\Hear You Me.mp3");
                string artist = mp3.Artist;

 

posted @ 2013-09-13 23:34  逍遥子k  阅读(453)  评论(0编辑  收藏  举报