Help with video playback problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fuzz13
    New Member
    • Jun 2010
    • 110

    #1

    Help with video playback problem.

    I have a project that has 4 radio buttons labeled with different animals. There are then 6 buttons and when a button is pressed based off of the radio button selected a picture will display and specific text will fill a label in the window.

    When the user selects Koala (radio button) and presses Talk (button) it will hide the picture box and unhide the object that houses the video.
    Code:
    else if (rbtnKoala.Checked == true)
                {
                    {
                        lblOutput.Text = Convert.ToString(reggie.Talk);
                        //hide the picture box
                        pictureBox1.Visible = false;
                        //make the video box visible
                        viewport.Visible = true;
    
    
                        // store the original size of the panel
                        int width = viewport.Width;
                        int height = viewport.Height;
    
                        //string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
    
    
                        string directory = //directory of file.
                        // load the selected video file
                        video = new Video(directory);
    
                        // 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);
    
                        video.Play();
                    }
                }
    When I then click any other button/animal combination the video is hidden but still audible. I implemented an if-then statement to check the playback state of the video and if it is not currently stopped then stop it.

    The problem becomes if the Koala.Talk has not been performed, the video is not established yet (I instantiated the Video video; earlier in the code though). If the video hasn't started at least once, it gives an error "Object reference not set to an instance of an object." I believe it is because it can't check the videos playback state without it first having been told to play. Here is my if-then statement to check it.

    Code:
    //this stops the video of koala.talk if it is playing when this button is clicked
                if (video.State != StateFlags.Stopped)
                {
                    video.Stop();
                }
    How do I code it to check the playback state, and/or check if the video has been played/established? I want it to reach the code after the if-then statement if the video hasn't been played/playing yet.

    Thanks in advance.
  • Fuzz13
    New Member
    • Jun 2010
    • 110

    #2
    I apparently just needed to write it all out because I just figured out how to do what I wanted.

    I established a bool koalaTalkPlayed = false; and in the Koala Talk expression I change the value to true. Then in my test it now shows:
    Code:
         if (koalaTalkPlayed == true)
                {
                    //this stops the video of koala.talk if it is playing when this button is clicked
                    if (video.State != StateFlags.Stopped)
                    {
                        video.Stop();
                    }
                }
    If the video has been played, make sure it gets stopped before changing the picture and text. If it hasn't been played then it bypasses the inside test because it fails the first if-then expression.

    Hope this can help someone else. Thanks.

    Comment

    Working...