public void DoTests() { Config(); m_edit.OpenEx(sFileName, MetaDataAccess.Read, MetaDataShare.Read); m_edit.Close(); }
public Metadata GetMetadata(object target) { if (target == null || !(target is string)) { return(null); } string filename = target.ToString(); IWMMetadataEditor2 metadataEditor = null; IWMSyncReader syncReader = null; WMMetadata metadata = new WMMetadata(); try { WMFSDKFunctions.WMCreateEditor(out metadataEditor); metadataEditor.OpenEx(filename, FILE_ACCESS.GENERIC_READ, FILE_SHARE.FILE_SHARE_NONE); IWMHeaderInfo3 header = (IWMHeaderInfo3)metadataEditor; ushort attributeCount; header.GetAttributeCountEx(StreamNumber, out attributeCount); for (int i = 0; i < attributeCount; i++) { MetadataField metadataField = GetAttributeByIndex(header, i); metadata.AddMetadataField(metadataField); } } catch (COMException ex) { // TODO: Logging } finally { if (metadataEditor != null) { metadataEditor.Close(); Marshal.FinalReleaseComObject(metadataEditor); metadataEditor = null; } } try { WMFSDKFunctions.WMCreateSyncReader(IntPtr.Zero, WMT_RIGHTS.WMT_RIGHT_PLAYBACK, out syncReader); syncReader.Open(filename); int outputCount; syncReader.GetOutputCount(out outputCount); IWMOutputMediaProps outputMediaProps = null; for (uint i = 0; i < outputCount; i++) { IWMOutputMediaProps innerOutputMediaProps; syncReader.GetOutputProps(i, out innerOutputMediaProps); Guid type; innerOutputMediaProps.GetType(out type); if (type == WMFSDKFunctions.WMMEDIATYPE_Video) { outputMediaProps = innerOutputMediaProps; break; } } if (outputMediaProps != null) { int pcbType = 0; outputMediaProps.GetMediaType(IntPtr.Zero, ref pcbType); IntPtr mediaTypeBufferPtr = Marshal.AllocHGlobal(pcbType); outputMediaProps.GetMediaType(mediaTypeBufferPtr, ref pcbType); WM_MEDIA_TYPE mediaType = new WM_MEDIA_TYPE(); WMVIDEOINFOHEADER videoInfoHeader = new WMVIDEOINFOHEADER(); Marshal.PtrToStructure(mediaTypeBufferPtr, mediaType); Marshal.FreeHGlobal(mediaTypeBufferPtr); Marshal.PtrToStructure(mediaType.pbFormat, videoInfoHeader); double frameRate = Math.Round((double)10000000 / videoInfoHeader.AvgTimePerFrame, 2); metadata.AddMetadataField(new MetadataField("FrameRate", frameRate)); } } catch (COMException ex) { // TODO: Logging } finally { if (syncReader != null) { syncReader.Close(); Marshal.FinalReleaseComObject(syncReader); syncReader = null; } } return(metadata); }