【问题标题】:c# using Microsoft.DirectX.AudioVideoPlayback how to play next video after one is finishedc# using Microsoft.DirectX.AudioVideoPlayback 如何在一个视频完成后播放下一个视频
【发布时间】:2011-04-05 08:20:19
【问题描述】:

我可以在我的 Windows 窗体中放一个视频。

我的问题是,当它播放完视频,它开始播放另一个视频时,我该怎么做?意思是像一个序列。完成后,播放另一个视频。

到目前为止,我已经设法播放视频,它只是循环播放视频。

有什么想法吗?

这是我目前的代码:

public partial class Form1 : Form
{
     Video video;



    public Form1()
    {
        InitializeComponent();          
        Initializevid1();

    }

    public void Initializevid1()
    {

           // store the original size of the panel
            int width = viewport.Width;
            int height = viewport.Height;

            // load the selected video file
            video = new Video("C:\\Users\\Dave\\Desktop\\WaterDay1.wmv");

            // set the panel as the video object’s owner
            video.Owner = viewport;

            // stop the video
            video.Play();
            video.Ending +=new EventHandler(BackLoop);

            // resize the video to the size original size of the panel
            viewport.Size = new Size(width, height);   

    }

    private void BackLoop(object sender, EventArgs e)
    {

        //video.CurrentPosition = 0;
    }

【问题讨论】:

  • 视口是什么类型的控件?

标签: c# winforms video directx audiovideoplayback


【解决方案1】:

在 AudioVideoPlayback 中播放视频序列时:

  1. 创建要显示的视频列表(使用文件路径),最好在列表框中。

  2. 使用整数从 listbox.items 索引中获取文件路径。

  3. 确保在加载下一个视频之前处理视频。

  4. 每次播放视频时递增整数。

  5. 使用 if 语句查看是否是序列的结尾。

  6. 作为个人喜好(不确定它有多大不同),我会在播放前调整视频大小

所以从您的代码来看:(尚未对此进行测试,但理论上,我认为它应该可以工作)

    public partial class Form1 : Form
    {
        Video video;
        Int SeqNo = 0;

        public Form1()
        {
            InitializeComponent();          
            Initializevid1();

        }

        public void Initializevid1()
        {

               // store the original size of the panel
                int width = viewport.Width;
                int height = viewport.Height;

                // load the selected video file
                video = new Video(listbox1.Items[SeqNo].Text);

                // set the panel as the video object’s owner
                video.Owner = viewport;

                // resize the video to the size original size of the panel
                viewport.Size = new Size(width, height);   

                // stop the video
                video.Play();

                // start next video
                video.Ending +=new EventHandler(BackLoop);
        }

        private void BackLoop(object sender, EventArgs e)
        {
            // increment sequence number
            SeqNo += 1;            //or '++SeqNo;'

            //check video state
            if (!video.Disposed)
            {
                video.Dispose();
            }

            //check SeqNo against listbox1.Items.Count -1 (-1 due to SeqNo is a 0 based index)
            if (SeqNo <= listbox1.Items.Count -1)
            {


               // store the original size of the panel
                int width = viewport.Width;
                int height = viewport.Height;

                // load the selected video file
                video = new Video(listbox1.Items[SeqNo].Text);

                // set the panel as the video object’s owner
                video.Owner = viewport;

                // resize the video to the size original size of the panel
                viewport.Size = new Size(width, height);   

                // stop the video
                video.Play();


                // start next video
                video.Ending +=new EventHandler(BackLoop);
           }
        }

【讨论】:

    【解决方案2】:

    您可以使用之前创建的相同视频对象在BackLoop() 函数中打开第二个视频文件。

    所以,代码应该是这样的:

    private void BackLoop(object sender, EventArgs e)
    {
        video.Open("C:\\Users\\Dave\\Desktop\\WaterDay2.wmv", true);
    }
    

    【讨论】:

      【解决方案3】:

      我使用这篇文章来适应我的需要,这是我的解决方案:

      Video _SegaVideo;
      Video _IntroVideo;
      
      public _FrmMain()
      {
          InitializeComponent();
      
          _SegaVideo = new Video(@"video\SEGA.AVI");
          _SegaVideo.Owner = _VideoPanel;
          _SegaVideo.Play();
          _SegaVideo.Ending += new EventHandler(_SegaVideoEnding);
      
      }
      
      private void _SegaVideoEnding(object sender, EventArgs e)
      {
          _IntroVideo = new Video(@"video\INTRO.AVI");
          _IntroVideo.Owner = _VideoPanel;
          _IntroVideo.Play();
      }
      

      【讨论】:

        猜你喜欢
        • 2018-03-21
        • 1970-01-01
        • 2012-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 2015-11-26
        相关资源
        最近更新 更多