简体   繁体   中英

C#/Windows MediaPlayer: Handle clicks on buttons

Simple question: I have an AxWindowsMediaPlayer component and I want to modify the OnPlayButtonClick event, which does not seem to exist. Any idea of a work around?

It should be something in terms of this:

private void OnPlayButtonClick() {
  MessageBox.Show('Hello World');
  if (wmPlayer.playState.ToString().Equals("wmppsPlaying"))
    wmPlayer.Ctlcontrols.pause();
  else
    wmPlayer.Ctlcontrols.play();
}

You could select that control and look at the properties windows and click the lightening bolt you will see all the events you can subscribe to for that control. I dont think there is an playbuttonclick event you can subscribe to, I think you would need to subscribe to playstatechanged and at that point check the play state and perform operations based off what it is. You could do something like this:

private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        MessageBox.Show(e.newState.ToString());
    }

Or you could create custom buttoms to perform the play, pause, stop functions and perform what ever actions needed in the event handlers of those buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM