Lucas Juan
Lucas Juan

Reputation: 371

How to stop the media player in c# when the form is not active?

I have embedded a media player (axWindowsMediaPlayer) in my c# winform application. It loops and plays fine. The problem is when the form where it was located will be closed or hide. It still plays the video even the form is not active. How can I stop it when the form where it is placed is not active anymore?

Upvotes: 0

Views: 1096

Answers (1)

Rama Kathare
Rama Kathare

Reputation: 930

If you want to stop the Player when the form is minimized, you can do it by

private void Form_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        //Do your stuff
    }
}

Or, you want to stop the player when ever the form is not active you may try the following code

private void Form_Deactivate(object sender, EventArgs e)
{
    //Do your stuff
}

Upvotes: 2

Related Questions