2013-05-06 6 views
1
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; 
} 

외부 라이브러리 또는 Shell32없이 ID3v2.3 태그를 읽는 코드를 작성하고 있습니다.Id3v2 태그를 읽는 방법

위 코드는 코드이지만 올바르게 작동하지 않는 것 같습니다.

프레임 데이터 크기 : 91

01-FF-FE-52-00-6F-00-63-00-6B- 나는이 코드를 실행하면 다음

결과입니다 00-20-00-6E-00-27-00-20-00-52-00-6F-00-6C-00-6C-00-20-00-28-> 00-57-00-69-00 -6C-00-6C-00-20-00-54-00-61-00-6B-00-65-00-20-00-59-00-6F-00-75-00-20-00-74 -> 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

태그에 녹음 된 노래 제목 "Rock n 'Roll (Will Take You to the Mountain)"을 반환하지 않습니다.

무엇이 문제인가?

답변

5

시작 부분의 01은 UTF-16 (문자 당 2 바이트)으로 인코딩되었음을 나타냅니다. 다음 2 바이트 인 FF FE는 바이트 순서 표시이므로 가장 중요한 첫 번째 또는 가장 중요한 첫 번째 바이트 쌍으로 해석할지 여부를 알 수 있습니다. 그 후에는 실제 텍스트 데이터가 있습니다.

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