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";

结构图:

WMA文件的文件头结构 - 乂乂 - 一个人,一支烟  ·~~

写入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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值