首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Microsoft.DirectX.AudioVideoPlayback的c#如何在一个视频结束后播放下一个视频

使用Microsoft.DirectX.AudioVideoPlayback的c#如何在一个视频结束后播放下一个视频
EN

Stack Overflow用户
提问于 2011-04-05 16:20:19
回答 3查看 7.3K关注 0票数 1

我可以将视频放到我的windows窗体中。

我的问题是,当它播放完视频后,它开始播放另一个视频时,我如何制作它?意思就像是在一个序列中。完成后,播放另一个视频。

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

有什么想法吗?

这是我到目前为止的代码:

代码语言:javascript
复制
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;
    }
EN

回答 3

Stack Overflow用户

发布于 2012-06-06 18:57:04

在AudioVideoPlayback中播放视频序列时:

  1. 创建要显示的视频列表(使用文件路径),最好是在列表框中。
  2. 使用整数从listbox.items索引中获取文件路径。
  3. 确保在每次播放视频时加载下一个video.
  4. Increment整数之前处理视频。
  5. 使用if语句查看是否为序列的结尾。
  6. 作为个人偏好(不确定它有多大不同),我会在播放

之前调整视频的大小

所以从你的代码中可以看出:(我还没有测试过,但理论上,我认为它应该可以工作)

代码语言:javascript
复制
    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);
           }
        }
票数 1
EN

Stack Overflow用户

发布于 2012-03-07 19:39:02

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

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

代码语言:javascript
复制
private void BackLoop(object sender, EventArgs e)
{
    video.Open("C:\\Users\\Dave\\Desktop\\WaterDay2.wmv", true);
}
票数 0
EN

Stack Overflow用户

发布于 2013-07-07 12:52:55

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

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5549084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档