简体   繁体   English

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

[英]c# using Microsoft.DirectX.AudioVideoPlayback how to play next video after one is finished

i am able to put a video in my windows form. 我可以将视频放入Windows窗体中。

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

When playing video sequences in AudioVideoPlayback: 在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. 使用整数从listbox.items索引获取文件路径。

  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. 使用if语句查看它是否是序列的结尾。

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

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

You can use the same video object created earlier to open the second video file in the BackLoop() function. 您可以使用先前创建的相同视频对象在BackLoop()函数中打开第二个视频文件。

So, the code should look like something this: 因此,代码应如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#winform,使用Microsoft.DirectX.AudioVideoPlayback dll中的Video / Audio类后,应用程序崩溃 - C# winform, App Crashing after using the Video/Audio classes from the Microsoft.DirectX.AudioVideoPlayback dll Activemovie窗口在C#中弹出Microsoft.DirectX.AudioVideoPlayback - Activemovie window pop up Microsoft.DirectX.AudioVideoPlayback in C# 使用Microsoft.DirectX.AudioVideoPlayback播放视频时出错; 程序集版本错误 - Error playing video using Microsoft.DirectX.AudioVideoPlayback; assembly version error 通过Microsoft.DirectX.AudioVideoPlayback显示对视频播放的控制 - Display a Control over video playing via Microsoft.DirectX.AudioVideoPlayback SharpDX中的Microsoft.DirectX.AudioVideoPlayback替代 - Microsoft.DirectX.AudioVideoPlayback alternative in SharpDX Microsoft.DirectX.AudioVideoPlayback程序不起作用 - Microsoft.DirectX.AudioVideoPlayback program not working C#Microsoft.DirectX.AudioVideoPlayback.Video参考? - C# Microsoft.DirectX.AudioVideoPlayback.Video reference? 找不到参考Microsoft.DirectX.AudioVideoPlayback - Can't find reference Microsoft.DirectX.AudioVideoPlayback 找不到引用Microsoft.DirectX.AudioVideoPlayback和Microsoft.DirectX - can't find references Microsoft.DirectX.AudioVideoPlayback and Microsoft.DirectX 在 C# WinForm 中使用 DirectX 播放视频 - Play video using DirectX in C# WinForm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM