English version Versión en español Version française
 


Code samples related with the article: C Sharp Windows Media Format SDK Translation

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

Indexing and ASF file
The following code shows a simple way to index and ASF file. Indexing could be needed if you use the WmaWriter class to obtain an ASF file and you plan using it in some kind of devices (Pocket PC, for instance). When using custom writer sinks, as in WmaWriter class, the resulting idexing isn't as using file writer wink (as in IWMWriter.SetOutputFilename method).


/// <summary>
/// Utility class to handle indexer notification. This class should be
/// extended to obtain more complet status handling.
/// </summary>
public class IndexerCallback : IWMStatusCallback
{
  private System.Threading.ManualResetEvent m_Event = new System.Threading.ManualResetEvent(false);

  public IndexerCallback()
  {
  }
  
  public bool Finished 
  {
    get { return m_Event.WaitOne(0, false); } 
  }

  public bool WaitForCompletion(int Timeout)
  {
    return m_Event.WaitOne(Timeout, false);
  }

  public bool WaitForCompletion()
  {
    return m_Event.WaitOne();
  }
  #region IWMStatusCallback Members

  public void OnStatus(Yeti.WMFSdk.WMT_STATUS Status, 
	              System.IntPtr hr,
	              Yeti.WMFSdk.WMT_ATTR_DATATYPE dwType, 
	              System.IntPtr pValue, 
	              System.IntPtr pvContext)
  {
    switch(Status)
    {
      case WMT_STATUS.WMT_ERROR:
      case WMT_STATUS.WMT_CLOSED:
        m_Event.Set();
        break;
    }
  }
  #endregion
}
...
//Use the following code to index a file
IWMIndexer Indexer = WM.CreateIndexer();
IndexerCallback Callback = new IndexerCallback();

(Indexer as IWMIndexer2).Configure(0, WMT_INDEXER_TYPE.WMT_IT_PRESENTATION_TIME, 
                                   IntPtr.Zero, IntPtr.Zero);

Indexer.StartIndexing("SomeFile.wma", Callback, IntPtr.Zero);

Callback.WaitForCompletion();
  Copyright © Idael Cardoso. All rights reserved.