/////////////////////////////////////////////////////////////////////// // Name: CreateWavFile // Description: Creates a .wav file from an input file. /////////////////////////////////////////////////////////////////////// static void CreateWavFile(string sURL, string sOutputFile) { IMFByteStream pStream = null; IMFMediaSinkAlt pSink = null; IMFMediaSource pSource = null; IMFTopology pTopology = null; WavSinkNS.CWavSink pObj = null; HResult hr = MFExtern.MFCreateFile(MFFileAccessMode.Write, MFFileOpenMode.DeleteIfExist, MFFileFlags.None, sOutputFile, out pStream); MFError.ThrowExceptionForHR(hr); try { pObj = new WavSinkNS.CWavSink(pStream); pSink = pObj as IMFMediaSinkAlt; // Create the media source from the URL. CreateMediaSource(sURL, out pSource); // Create the topology. CreateTopology(pSource, pSink, out pTopology); // Run the media session. RunMediaSession(pTopology); hr = pSource.Shutdown(); MFError.ThrowExceptionForHR(hr); } finally { if (pStream != null) { Marshal.ReleaseComObject(pStream); } if (pSource != null) { Marshal.ReleaseComObject(pSource); } if (pTopology != null) { Marshal.ReleaseComObject(pTopology); } //pObj.Dispose(); } }
/////////////////////////////////////////////////////////////////////// // Name: CreateWavFile // Description: Creates a .wav file from an input file. /////////////////////////////////////////////////////////////////////// static void CreateWavFile(string sURL, string sOutputFile) { IMFByteStream pStream = null; IMFMediaSinkAlt pSink = null; IMFMediaSource pSource = null; IMFTopology pTopology = null; WavSinkNS.CWavSink pObj = null; int hr = MFExtern.MFCreateFile(MFFileAccessMode.Write, MFFileOpenMode.DeleteIfExist, MFFileFlags.None, sOutputFile, out pStream); MFError.ThrowExceptionForHR(hr); try { pObj = new WavSinkNS.CWavSink(pStream); pSink = pObj as IMFMediaSinkAlt; // Create the media source from the URL. CreateMediaSource(sURL, out pSource); // Create the topology. CreateTopology(pSource, pSink, out pTopology); // Run the media session. RunMediaSession(pTopology); hr = pSource.Shutdown(); MFError.ThrowExceptionForHR(hr); } finally { if (pStream != null) { Marshal.ReleaseComObject(pStream); } if (pSource != null) { Marshal.ReleaseComObject(pSource); } if (pTopology != null) { Marshal.ReleaseComObject(pTopology); } //pObj.Dispose(); } }