How to change a video once the current has stopped?

114 Views Asked by At

I am currently working with .NET 4.5. Programming a photobooth. The photobooth should start wit fullscreen:

  1. Show an Intro screen with an intro video.
  2. When the user clicks on the screen, it has to show a get ready! video
  3. When the get ready video finishes playing, it has to show a countdown video
  4. When the countdown video finishes, it has to take a picture.

Right now I can do #1 and #2. I can also take pictures. My problem is with the sequence. Once a video finishes, I need to change the video, but since everything runs in the event handler, it only plays the video WHILE the program is running the event handler.

Is there any better and smarter way to do this?

Here is my code:

What I have and works right now:

private void Form1_Load(object sender, EventArgs e)
        {
            // maximize the screen
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            TopMost = true;

            // play an intro video without the UI controls
            this.videoPath = this.basePath + "intro.mp4";
            this.wmpVideo.URL = this.videoPath;
            this.wmpVideo.settings.setMode("Loop", true);
            this.wmpVideo.Ctlcontrols.play();
            this.wmpVideo.uiMode = "none";

        }

Then, if the user clicks on the video, it will change the video to a new file:

private void wmpVideo_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
    {
        if (this.current == 0) //this means that currently we are in the intro
        {
            // Then I change the video to "get ready!"
            this.changeVideo("getready.mp4",1);
        }

changeVideo basically updates the video to getready.mp4. Then, I need it to change it to countdown.mp4. In order to move from one video to another, I need to check when the video finishes. I do this right now with:

wmpVideo.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(checkGetReadyFinished);

And the event handler looks like this:

private void checkGetReadyFinished(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    if (e.newState == 8) { 
        // If we are currently in the "getready state"
        if (this.current == 1)
        {
            // then I change the video to the countdown.mp4
            this.changeVideo("countdown.mp4", 2);
        }

    }
}

PROBLEM

I noticed the video ONLY plays when I am on the event handler method. I realized this because I saw that no video was played, so I added a MessageBox in the changeVideo method. I saw that as long as the MessageBox was showing, the video was playing. When I clicked "OK", the video disappeared I.E., I need to stay in the event handler method.

QUESTION

Is there any other better way to show a video1, then show video2 when video1 finishes. As I mentioned, I need to do a photobooth program.

I also tried calling another form, but as soon as I set it to fullscreen, the screen sort of flashes.

Is there any optimal way of doing this?

0

There are 0 best solutions below