コード例 #1
0
        private void FileCompleted(object o, System.EventArgs e)
        {
            FileCompletedArgs ca = e as FileCompletedArgs;

            tbStatus.Text = string.Format("Finished file: {0}", ca.FileName);
            Debug.WriteLine(string.Format("{0} {1}", ca.FileName, ca.Type));
        }
コード例 #2
0
        /// <summary>
        /// Called on a new thread to process events from the graph.  The thread
        /// exits when the graph finishes.  Cancelling is done here.
        /// </summary>
        private void EventWait()
        {
            // Returned when GetEvent is called but there are no events
            const int E_ABORT = unchecked ((int)0x80004004);

            int       hr;
            IntPtr    p1, p2;
            EventCode ec;
            EventCode exitCode = 0;

            IMediaEvent pEvent = (IMediaEvent)m_pGraph;

            do
            {
                // Read the event
                for (
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100);
                    hr >= 0 && m_State < ClassState.GraphCompleted;
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100)
                    )
                {
                    switch (ec)
                    {
                    case EventCode.UserAbort:
                        ChangeState(ClassState.Cancelling);
                        exitCode = ec;
                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);

                        break;

                    // If the clip is finished playing
                    case EventCode.Complete:
                    case EventCode.ErrorAbort:
                        ChangeState(ClassState.GraphCompleting);
                        exitCode = ec;

                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);
                        break;

                    // Walked past the end of a video file, send an event
                    case EC_VideoFileComplete:
                        if (FileCompleted != null)
                        {
                            MediaFile         mf = m_Video.File(p1.ToInt32());
                            FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Video);
                            FileCompleted(this, ca);
                        }
                        break;

                    // Walked past the end of a video file, send an event
                    case EC_AudioFileComplete:
                        if (FileCompleted != null)
                        {
                            MediaFile         mf = m_Audio.File(p1.ToInt32());
                            FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Audio);
                            FileCompleted(this, ca);
                        }
                        break;

                    default:
                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DESError.ThrowExceptionForHR(hr);
                        break;
                    }
                }

                // If the error that exited the loop wasn't due to running out of events
                if (hr != E_ABORT)
                {
                    DESError.ThrowExceptionForHR(hr);
                }
                //FilterState fs;
                //m_pControl.GetState(200, out fs);
                ////DESError.ThrowExceptionForHR(hr);
            } while (m_State < ClassState.GraphCompleting);

            // If the user cancelled
            if (m_State == ClassState.Cancelling && m_pControl != null)
            {
                // Stop the graph, send an appropriate exit code
                hr       = m_pControl.Stop();
                exitCode = EventCode.UserAbort;
            }

            if (m_State == ClassState.GraphCompleting)
            {
                m_State = ClassState.GraphCompleted;
            }
            else
            {
                m_State = ClassState.Cancelled;
            }

            threadCompleted = true;

            // Send an event saying we are complete
            if (this.ThreadFinished != null)
            {
                DESCompletedArgs ca = new DESCompletedArgs(exitCode);
                this.ThreadFinished(this, ca);
            }
        } // Exit the thread
コード例 #3
0
        private void FileCompleted(object sender, System.EventArgs e)
        {
            FileCompletedArgs ca = e as FileCompletedArgs;

            Console.WriteLine("Finished File" + ca.FileName);
        }
コード例 #4
0
ファイル: DESCombine.cs プロジェクト: DeSciL/Ogama
    /// <summary>
    /// Called on a new thread to process events from the graph.  The thread
    /// exits when the graph finishes.  Cancelling is done here.
    /// </summary>
    private void EventWait()
    {
      // Returned when GetEvent is called but there are no events
      const int E_ABORT = unchecked((int)0x80004004);

      int hr;
      IntPtr p1, p2;
      EventCode ec;
      EventCode exitCode = 0;

      IMediaEvent pEvent = (IMediaEvent)m_pGraph;

      do
      {
        // Read the event
        for (
            hr = pEvent.GetEvent(out ec, out p1, out p2, 100);
            hr >= 0 && m_State < ClassState.GraphCompleted;
            hr = pEvent.GetEvent(out ec, out p1, out p2, 100)
            )
        {
          switch (ec)
          {
            case EventCode.UserAbort:
              ChangeState(ClassState.Cancelling);
              exitCode = ec;
              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);

              break;
            // If the clip is finished playing
            case EventCode.Complete:
            case EventCode.ErrorAbort:
              ChangeState(ClassState.GraphCompleting);
              exitCode = ec;

              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);
              break;

            // Walked past the end of a video file, send an event
            case EC_VideoFileComplete:
              if (FileCompleted != null)
              {
                MediaFile mf = m_Video.File(p1.ToInt32());
                FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Video);
                FileCompleted(this, ca);
              }
              break;

            // Walked past the end of a video file, send an event
            case EC_AudioFileComplete:
              if (FileCompleted != null)
              {
                MediaFile mf = m_Audio.File(p1.ToInt32());
                FileCompletedArgs ca = new FileCompletedArgs(mf.FileName, FileCompletedArgs.FileType.Audio);
                FileCompleted(this, ca);
              }
              break;

            default:
              // Release any resources the message allocated
              hr = pEvent.FreeEventParams(ec, p1, p2);
              DESError.ThrowExceptionForHR(hr);
              break;
          }
        }

        // If the error that exited the loop wasn't due to running out of events
        if (hr != E_ABORT)
        {
          DESError.ThrowExceptionForHR(hr);
        }
        //FilterState fs;
        //m_pControl.GetState(200, out fs);
        ////DESError.ThrowExceptionForHR(hr);

      } while (m_State < ClassState.GraphCompleting);

      // If the user cancelled
      if (m_State == ClassState.Cancelling && m_pControl != null)
      {
        // Stop the graph, send an appropriate exit code
        hr = m_pControl.Stop();
        exitCode = EventCode.UserAbort;
      }

      if (m_State == ClassState.GraphCompleting)
      {
        m_State = ClassState.GraphCompleted;
      }
      else
      {
        m_State = ClassState.Cancelled;
      }

      threadCompleted = true;

      // Send an event saying we are complete
      if (this.ThreadFinished != null)
      {
        DESCompletedArgs ca = new DESCompletedArgs(exitCode);
        this.ThreadFinished(this, ca);
      }
    } // Exit the thread