// PlayStateChangeHandler(sender, e) is dispatched when a change in the current play // state is detected. private void PlayStateChangeHandler(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { WMPPlayState stateObject = (WMPPlayState)e.newState; if (stateObject == WMPPlayState.wmppsStopped) { _player.close(); } else if (stateObject == WMPPlayState.wmppsPaused) { Pause(stateObject); } }
private void SynthesizeAndPlayButton_Click(object sender, EventArgs e) { // generate the synthesis text if (tabControl1.SelectedTab == tabControl1.TabPages["Bank"]) { SynthesizeRichTextBox.Text = "请顾客" + CustomNoComboBox.Text + "到" + WindowNoComboBox.Text + "窗口办理业务"; } else { SynthesizeRichTextBox.Text = "从北京到上海的航班" + AirPlaneComboBox.Text + "马上就要起飞了, 请还没登机的乘客到登机口" + GateNoComboBox.Text + "办理登机手续"; } mediaPlayer.Ctlcontrols.stop(); mediaPlayer.close(); SynthesizePlay(); }
public void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Memory Leaks in Window Media Player + c# // https://www.codeproject.com/Questions/155836/Memory-Leaks-in-Window-Media-Player-c // https://www.codeproject.com/Questions/610465/MemoryplusLeaksplusinplusWindowplusMediaplusPlayer // Dispose of the Windows Media Player as the form is closing // // Note: The Form.Closed and Form.Closing events are not raised when the // Application.Exit method is called to exit an application. // If Application.Exit is to be used, you should call the Form.Close method // before calling the Application.Exit method. // if (this.Controls.ContainsKey("m_media")) { this.Controls.RemoveByKey("m_media"); // Remove from Conrols collection m_media.close(); // Close the Windows Media Player control m_media.Dispose(); // Dispose m_media = null; } GC.Collect(); // Start .NET CLR Garbage Collection GC.WaitForPendingFinalizers(); // Wait for Garbage Collection to finish }