//------------------------------------------------------------------------------
        // Name: DeleteAttrib()
        // Desc: Delete the attribute at the specified index.
        //------------------------------------------------------------------------------
        bool DeleteAttrib(string pwszFileName, ushort wStreamNum, ushort wAttribIndex)
        {
            try
            {
                IWMMetadataEditor MetadataEditor;
                IWMHeaderInfo3    HeaderInfo3;

                WMFSDKFunctions.WMCreateEditor(out MetadataEditor);

                MetadataEditor.Open(pwszFileName);

                HeaderInfo3 = ( IWMHeaderInfo3 )MetadataEditor;

                HeaderInfo3.DeleteAttribute(wStreamNum, wAttribIndex);

                MetadataEditor.Flush();

                MetadataEditor.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }

            return(true);
        }
        //------------------------------------------------------------------------------
        // Name: ShowAttributes3()
        // Desc: Displays all attributes for the specified stream, with support
        //       for GetAttributeByIndexEx.
        //------------------------------------------------------------------------------
        bool ShowAttributes3(string pwszFileName, ushort wStreamNum)
        {
            try
            {
                IWMMetadataEditor MetadataEditor;
                IWMHeaderInfo3    HeaderInfo3;
                ushort            wAttributeCount = 0;

                WMFSDKFunctions.WMCreateEditor(out MetadataEditor);

                MetadataEditor.Open(pwszFileName);

                HeaderInfo3 = ( IWMHeaderInfo3 )MetadataEditor;

                HeaderInfo3.GetAttributeCountEx(wStreamNum, out wAttributeCount);

                PrintListHeader();

                for (ushort wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++)
                {
                    WMT_ATTR_DATATYPE wAttribType;
                    ushort            wLangIndex     = 0;
                    string            pwszAttribName = null;
                    byte[]            pbAttribValue  = null;
                    ushort            wAttribNameLen = 0;
                    uint dwAttribValueLen            = 0;

                    HeaderInfo3.GetAttributeByIndexEx(wStreamNum,
                                                      wAttribIndex,
                                                      pwszAttribName,
                                                      ref wAttribNameLen,
                                                      out wAttribType,
                                                      out wLangIndex,
                                                      pbAttribValue,
                                                      ref dwAttribValueLen);

                    pwszAttribName = new String(( char )0, wAttribNameLen);
                    pbAttribValue  = new byte[dwAttribValueLen];

                    HeaderInfo3.GetAttributeByIndexEx(wStreamNum,
                                                      wAttribIndex,
                                                      pwszAttribName,
                                                      ref wAttribNameLen,
                                                      out wAttribType,
                                                      out wLangIndex,
                                                      pbAttribValue,
                                                      ref dwAttribValueLen);

                    PrintAttribute(wAttribIndex, wStreamNum, pwszAttribName, wAttribType, 0, pbAttribValue, dwAttribValueLen);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        public void GetMetadata()
        {
            try
            {
                String filename   = @"E:\Music\Album Leaf\Vermillion .WMA";
                ushort wStreamNum = 0;

                IWMMetadataEditor MetadataEditor;
                IWMHeaderInfo3    HeaderInfo3;
                ushort            wAttributeCount;

                WMFSDKFunctions.WMCreateEditor(out MetadataEditor);

                MetadataEditor.Open(filename);

                HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;

                HeaderInfo3.GetAttributeCount(wStreamNum, out wAttributeCount);

                PrintListHeader();

                for (ushort wAttribIndex = 0; wAttribIndex < wAttributeCount; wAttribIndex++)
                {
                    WMT_ATTR_DATATYPE wAttribType;
                    string            pwszAttribName  = null;
                    byte[]            pbAttribValue   = null;
                    ushort            wAttribNameLen  = 0;
                    ushort            wAttribValueLen = 0;

                    HeaderInfo3.GetAttributeByIndex(wAttribIndex,
                                                    ref wStreamNum,
                                                    pwszAttribName,
                                                    ref wAttribNameLen,
                                                    out wAttribType,
                                                    pbAttribValue,
                                                    ref wAttribValueLen);

                    pbAttribValue  = new byte[wAttribValueLen];
                    pwszAttribName = new String((char)0, wAttribNameLen);

                    HeaderInfo3.GetAttributeByIndex(wAttribIndex,
                                                    ref wStreamNum,
                                                    pwszAttribName,
                                                    ref wAttribNameLen,
                                                    out wAttribType,
                                                    pbAttribValue,
                                                    ref wAttribValueLen);

                    PrintAttribute(wAttribIndex, wStreamNum, pwszAttribName, wAttribType, 0, pbAttribValue, wAttribValueLen);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
        //------------------------------------------------------------------------------
        // Name: AddAttrib()
        // Desc: Add an attribute with the specifed language index.
        //------------------------------------------------------------------------------
        bool AddAttrib(string pwszFileName, ushort wStreamNum, string pwszAttribName,
                       ushort wAttribType, string pwszAttribValue, ushort wLangIndex)
        {
            try
            {
                IWMMetadataEditor MetadataEditor;
                IWMHeaderInfo3    HeaderInfo3;
                byte[]            pbAttribValue;
                int nAttribValueLen;
                WMT_ATTR_DATATYPE AttribDataType = ( WMT_ATTR_DATATYPE )wAttribType;
                ushort            wAttribIndex   = 0;

                if (!TranslateAttrib(AttribDataType, pwszAttribValue, out pbAttribValue, out nAttribValueLen))
                {
                    return(false);
                }

                WMFSDKFunctions.WMCreateEditor(out MetadataEditor);

                MetadataEditor.Open(pwszFileName);

                HeaderInfo3 = ( IWMHeaderInfo3 )MetadataEditor;

                HeaderInfo3.AddAttribute(wStreamNum,
                                         pwszAttribName,
                                         out wAttribIndex,
                                         AttribDataType,
                                         wLangIndex,
                                         pbAttribValue,
                                         (uint)nAttribValueLen);

                MetadataEditor.Flush();

                MetadataEditor.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }

            return(true);
        }