在图片框C#中播放视频时出现Microsoft.DirectX.DirectXException

时间:2016-02-14 22:12:51

标签: video directx picturebox playback

我在使用图片框控件播放DirectX视频时遇到问题。首先,我将视频作为参数传递给子表单的构造函数:

    public Microsoft.DirectX.AudioVideoPlayback.Video TPVideoPlayer;      //This is the player.

    public frmProjectInfo(clsGameInfo GameInfo)
    {
        InitializeComponent();

        if ( GameInfo.blTPVideoPresent == true)
            TPVideoPlayer = GameInfo.vidTPVideo;
     }

接下来,我将视频指定为在图片框控件中播放:

            if (TPVideoPlayer != null)
            {
                try
                {   
                    PanelWidth = pbTPImage.Width;
                    PanelHeight = pbTPImage.Height;
                    TPVideoPlayer = glbvidTPVideo;
                    TPVideoPlayer.Owner = pbTPImage;     //This is where the crash occurs. 
                    pbTPImage.Width = PanelWidth;
                    pbTPImage.Height = PanelHeight;
                    TPVideoPlayer.CurrentPosition = 0;
                    btnPlayTPMedia.Visible = btnPlayTPMedia.Enabled = true;
                }
                catch (ArgumentException e)
                {
                    MessageBox.Show(e.InnerException.ToString(), "oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TextBox txtbx = new TextBox();
                    txtbx.Text = e.ToString();
                    txtbx.SelectionLength = txtbx.TextLength;
                    txtbx.Copy();
                }
            }

子表单是一个对话框。当我单击确定按钮时,子窗体关闭,TPVideoPlayer设置的视频将返回到主窗体:

    public void ShowProjectInfoDialog()
    {
        frmProjectInfo ProjectInfo = new frmProjectInfo(GameInfo);
        if (DialogResult.OK == ProjectInfo.ShowDialog())
        {
            if (ProjectInfo.TPVideoPlayer != null)
                GameInfo.vidTPVideo = ProjectInfo.TPVideoPlayer;
         }
      }

接下来,当我使用上面的方法“ShowProjectInfoDialog”打开子窗体时,我的应用程序崩溃了。这是它抛出的异常:

Microsoft.DirectX.DirectXException occurred
  _HResult=-2147024809
  _message=Error in the application.
  HResult=-2147024809
  IsTransient=false
  Message=Error in the application.
  Source=Microsoft.DirectX.AudioVideoPlayback
  ErrorCode=-2147024809
  ErrorString=E_INVALIDARG
  StackTrace:
       at Microsoft.DirectX.AudioVideoPlayback.Video.set_Owner(Control value)
  InnerException: 

我无法获得内部异常信息,因为代码执行没有使它成为“catch”,我在Internet上找不到任何可以解释导致问题的原因。任何帮助将不胜感激。

0 个答案:

没有答案