C# 如何读取Id3v2标签 static void Main(字符串[]args) { FileStream fs=File.Open(@“C:\Skrillex-Rock n'Roll(将带你去山上).mp3”,FileMode.Open); BinaryReader br=新的BinaryReader(fs); 字节[]标记=新字节[3]; 字节[]版本=新字节[2]; 字节[]标志=新字节[1]; 字节[]大小=新字节[4]; 字节[]帧ID=新字节[4]; 字节[]帧大小=新字节[4]; 字节[]帧标志=新字节[2]; br.读取(标记,0,标记长度); br.Read(版本,0,版本.长度); br.Read(flags,0,flags.Length); br.读取(大小,0,大小.长度); br.Read(frameId,0,frameId.Length); br.Read(frameSize,0,frameSize.Length); br.Read(frameFlags,0,frameFlags.Length); ulong iSize=(ulong)框架尺寸[0]00-6F-00-20-00-74-00-68-00-65-00-20-00-4D-00-6F-00-75-00-6E-00-74-00-61-00-69-00-6E-00-29-00

C# 如何读取Id3v2标签 static void Main(字符串[]args) { FileStream fs=File.Open(@“C:\Skrillex-Rock n'Roll(将带你去山上).mp3”,FileMode.Open); BinaryReader br=新的BinaryReader(fs); 字节[]标记=新字节[3]; 字节[]版本=新字节[2]; 字节[]标志=新字节[1]; 字节[]大小=新字节[4]; 字节[]帧ID=新字节[4]; 字节[]帧大小=新字节[4]; 字节[]帧标志=新字节[2]; br.读取(标记,0,标记长度); br.Read(版本,0,版本.长度); br.Read(flags,0,flags.Length); br.读取(大小,0,大小.长度); br.Read(frameId,0,frameId.Length); br.Read(frameSize,0,frameSize.Length); br.Read(frameFlags,0,frameFlags.Length); ulong iSize=(ulong)框架尺寸[0]00-6F-00-20-00-74-00-68-00-65-00-20-00-4D-00-6F-00-75-00-6E-00-74-00-61-00-69-00-6E-00-29-00,c#,id3-tag,id3v2,C#,Id3 Tag,Id3v2,ÿþR 它不会返回标签中录制的歌曲标题“摇滚乐(将带你去山上)” 问题出在哪里?开头的01表示它被编码为UTF-16(每个字符2个字节)。接下来的两个字节FF FE是字节顺序标记,因此您可以判断是将字节对解释为最重要的第一个还是最不重要的第一个。之后,您就有了实际的文本数据 static void Main(string[] args) { FileStream fs = File.Open(@"C:\Skrillex - Rock n' Roll (Will Take You

ÿþR

它不会返回标签中录制的歌曲标题“摇滚乐(将带你去山上)”


问题出在哪里?

开头的01表示它被编码为UTF-16(每个字符2个字节)。接下来的两个字节FF FE是字节顺序标记,因此您可以判断是将字节对解释为最重要的第一个还是最不重要的第一个。之后,您就有了实际的文本数据

static void Main(string[] args)
{
    FileStream fs = File.Open(@"C:\Skrillex - Rock n' Roll (Will Take You to the Mountain).mp3", FileMode.Open);
    BinaryReader br = new BinaryReader(fs);

    byte[] tag = new byte[3];
    byte[] version = new byte[2];
    byte[] flags = new byte[1];
    byte[] size = new byte[4];
    byte[] frameId = new byte[4];
    byte[] frameSize = new byte[4];
    byte[] frameFlags = new byte[2];
        
    br.Read(tag, 0, tag.Length);
    br.Read(version, 0, version.Length);
    br.Read(flags, 0, flags.Length);
    br.Read(size, 0, size.Length);
    br.Read(frameId, 0, frameId.Length);
    br.Read(frameSize, 0, frameSize.Length);
    br.Read(frameFlags, 0, frameFlags.Length);

    ulong iSize = (ulong)frameSize[0] << 21 | (ulong)frameSize[1] << 14 | (ulong)frameSize[2] << 7 | (ulong)frameSize[3];
    Console.WriteLine("Frame Data Size : " + iSize.ToString());

    byte[] body = new byte[iSize];
    br.Read(body, 0, body.Length);
    Console.WriteLine(BitConverter.ToString(body));
    Console.WriteLine(ConvertHexToString(BitConverter.ToString(body)));

    br.Close();
}

public string ConvertHexToString(string HexValue)
{
    string StrValue = "";
    HexValue = HexValue.Replace("-", "");
    while (HexValue.Length > 0)
    {
        StrValue += Convert.ToChar(Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
        HexValue = HexValue.Substring(2, HexValue.Length - 2);
    }
    return StrValue;
}
等等

0052 - R
006F - o
0063 - c
006B - k