// FIXME this needs some work, to be completely in-tune with needs. public void MediaEventLoop(Action <double> UpdateProgress) { mediaEvent.CancelDefaultHandling(EventCode.StateChange); //mediaEvent.CancelDefaultHandling(EventCode.Starvation); while (stopMediaEventLoop == false) { try { EventCode ev; IntPtr p1, p2; if (mediaEvent.GetEvent(out ev, out p1, out p2, 0) == 0) { switch (ev) { case EventCode.Complete: Stopping.Fire(this, null); if (UpdateProgress != null) { UpdateProgress(source.PercentageCompleted); } return; case EventCode.StateChange: FilterState state = (FilterState)p1.ToInt32(); if (state == FilterState.Stopped || state == FilterState.Paused) { Stopping.Fire(this, null); } else if (state == FilterState.Running) { Starting.Fire(this, null); } break; // FIXME add abort and stuff, and propagate this. } // Trace.WriteLine(ev.ToString() + " " + p1.ToInt32()); mediaEvent.FreeEventParams(ev, p1, p2); } else { if (UpdateProgress != null) { UpdateProgress(source.PercentageCompleted); } // FiXME use AutoResetEvent Thread.Sleep(100); } } catch (Exception e) { Trace.WriteLine("MediaEventLoop: " + e); } } }