0

我正在编写一个读取 MP3 ID3v1 标签的程序。我的问题:DataGridView我得到一个标签值和不必要的符号“\0”。然而它不写流派!

这是我的代码:

  public class MusicID3Tag
        {

            public byte[] TAGID = new byte[3];      //  3
            public byte[] Title = new byte[30];     //  30
            public byte[] Artist = new byte[30];    //  30 
            public byte[] Album = new byte[30];     //  30 
            public byte[] Year = new byte[4];       //  4 
            public byte[] Comment = new byte[30];   //  30 
            public byte[] Genre = new byte[1];      //  1
        }

string[] fullfilesPath=Directory.GetFiles(folderBrowserDialog1.SelectedPath,"*.mp3*",SearchOption.AllDirectories);
int capacity = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.mp3*", SearchOption.AllDirectories).Length;
                        GlobalVariables.Var1 = capacity;
                        for (int i = 1; i <= capacity-1; i++)
                       {
                        string filePath = fullfilesPath[i];
                        using (FileStream fs = File.OpenRead(filePath))
                        {
                            if (fs.Length >= 128)
                            {
                            MusicID3Tag tag = new MusicID3Tag();

                            fs.Seek(-128, SeekOrigin.End);
                            fs.Read(tag.TAGID, 0, tag.TAGID.Length);
                            fs.Read(tag.Title, 0, tag.Title.Length);
                            fs.Read(tag.Artist, 0, tag.Artist.Length);
                            fs.Read(tag.Album, 0, tag.Album.Length);
                            fs.Read(tag.Year, 0, tag.Year.Length);
                            fs.Read(tag.Comment, 0, tag.Comment.Length);
                            fs.Read(tag.Genre, 0, tag.Genre.Length);
                            string theTAGID = Encoding.Default.GetString(tag.TAGID);

                            if (theTAGID.Equals("TAG"))
                            {

                                string Title = Encoding.Default.GetString(tag.Title);
                                string Artist = Encoding.Default.GetString(tag.Artist);
                                string Album = Encoding.Default.GetString(tag.Album);
                                string Year = Encoding.Default.GetString(tag.Year);
                                string Comment = Encoding.Default.GetString(tag.Comment);
                                string Genre = Encoding.Default.GetString(tag.Genre);
                                dt.Rows.Add(Artist, Title, Album, Year, Genre);
                                dataGridView1.DataSource = dt;
4

0 回答 0