c# 使用 Microsoft.DirectX.AudioVideoPlayback 如何在一个视频播放完毕后播放下一个视频

发布于 2024-10-30 12:54:38 字数 1082 浏览 8 评论 0原文

我可以将视频放入我的 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;
    }

i am able to put a video in my windows form.

my question is how do i make it when it finishes playing the video,it starts to play another video? meaning like in a sequence. after it finishes, play another video.

so far i have manage to play a video and it just loops the video.

any ideas?

this is my code so far:

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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜`诱少女 2024-11-06 12:54:38

在 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);
           }
        }

When playing video sequences in AudioVideoPlayback:

  1. Create a list of videos to be displayed (using file paths), preferably in a listbox.

  2. Use an integer to get file path from the listbox.items index.

  3. Ensure video is disposed before loading next video.

  4. Increment integer every time a video is played.

  5. Use an if statement to see if it is the end of the sequence.

  6. As a personal preference (not sure how much difference it makes) I would resize video before playing

So from your code: (haven't tested this, but in theory, I think it should work)

    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);
           }
        }
诗化ㄋ丶相逢 2024-11-06 12:54:38

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

因此,代码应该如下所示:

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

You can use the same video object created earlier to open the second video file in the BackLoop() function.

So, the code should look like something this:

private void BackLoop(object sender, EventArgs e)
{
    video.Open("C:\\Users\\Dave\\Desktop\\WaterDay2.wmv", true);
}
凌乱心跳 2024-11-06 12:54:38

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

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();
}

I used this post to adapt it to my needs and this was my solution:

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文