开发者

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.

my question is how do i make it w开发者_开发知识库hen 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:

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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜