WMA文件的文件头结构

转自:

http://zwkufo.blog.163.com/blog/static/258825120105303367352/

 

有关wma音频文件的文件结构,稍微整理一下,这些对读写wma文件信息都很有帮助。呵呵,有点乱,但是又没有时间细细解说,请见谅。如有任何指正,请留言交流。首先是几个GUID常量:

const string GUIDWmaST = "75B22630-668E-11CF-A6D9-00AA0062CE6C";
const string GUIDContentST = "75B22633-668E-11CF-A6D9-00AA0062CE6C";
const string GUIDExtContentST = "D2D0A440-E307-11D2-97F0-00A0C95EA850";
const string GUIDBrandST = "2211B3FA-BD23-11D2-B4B7-00A0C955FC6E";
const string GUIDFilePropertiesST = "8CABDCA1-A947-11CF-8EE4-00C00C205365";

结构图:

写入ExtContent信息示例(读取类似):

                    //no ExtContent Block we need add it
                    nNewHeaderObjects++;
                    int ExtContentPos = 16 + 8 + 4 + 2; // 设定ExtContent开始的位置
                    byte[] bLastData = new byte[fs.Length - ExtContentPos];
                    fs.Seek(ExtContentPos, SeekOrigin.Begin);
                    fs.Read(bLastData, 0, bLastData.Length);

                    //write new Header object count
                    fs.Seek(24, SeekOrigin.Begin);
                    byte[] bHeaderObjects = BitConverter.GetBytes(nNewHeaderObjects);
                    fs.Write(bHeaderObjects, 0, bHeaderObjects.Length);
                    bHeaderObjects = null;

                    int nAddLength = 0;
                    //we need add 'WM/AlbumTitle/0' tag
                    Int16 NewContents = 1;
                    byte[] bContents = BitConverter.GetBytes(NewContents);
                    nAddLength += 2;

                    string TagString = "WM/AlbumTitle/0";
                    byte[] bTagString = Encoding.Unicode.GetBytes(TagString);
                    Int16 nTagLen = (Int16)bTagString.Length;
                    nAddLength += 2;
                    nAddLength += (Int16)bTagString.Length;

                    Int16 nFlag = 0;
                    byte[] bFlag = BitConverter.GetBytes(nFlag);
                    nAddLength += 2;

                    byte[] bValueString = Encoding.Unicode.GetBytes(mInfo.AlbumeName + "/0");
                    Int16 nValueLen = (Int16)bValueString.Length;
                    nAddLength += 2;
                    nAddLength += bValueString.Length;

                    Int64 BlockLen = nAddLength + 24;
                    NewMaxSize += BlockLen;

                    //fs.Seek(NewMaxSize, SeekOrigin.Begin);
                    fs.Seek(ExtContentPos, SeekOrigin.Begin);

                    WriteGUID(fs, GUIDExtContentST);
                    //write new ExtContents block size
                    byte[] bnewLen = BitConverter.GetBytes(BlockLen);
                    fs.Write(bnewLen, 0, bnewLen.Length);
                    bnewLen = null;

                    //write content num
                    fs.Write(bContents, 0, bContents.Length);
                    bContents = null;

                    //write name len & name string
                    bnewLen = BitConverter.GetBytes(nTagLen);
                    fs.Write(bnewLen, 0, bnewLen.Length);
                    bnewLen = null;
                    fs.Write(bTagString, 0, bTagString.Length);
                    bTagString = null;

                    //write 2 byts flag
                    fs.Write(bFlag, 0, bFlag.Length);
                    bFlag = null;

                    //write value len & value strint
                    bnewLen = BitConverter.GetBytes(nValueLen);
                    fs.Write(bnewLen, 0, bnewLen.Length);
                    bnewLen = null;
                    fs.Write(bValueString, 0, bValueString.Length);
                    bValueString = null;

                    //write last data
                    fs.Write(bLastData, 0, bLastData.Length);
                    bLastData = null;

你可能感兴趣的:(技术,string,byte,null,header,object,c)