C#WindowsMediaPlayer没有在PlayStateChange上执行更改

时间:2012-03-01 17:29:12

标签: c# wmplib

我有一个在应用程序运行时创建的WMPLib.WindowsMediaPlayer实例。我想在播放器播放状态=“已停止”时隐藏面板。

这是我的代码:

private void PlayFile(String url)
{
    WMPLib.WindowsMediaPlayer Player = new WMPLib.WindowsMediaPlayer();
    Player.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
    Player.MediaError += new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
    Player.URL = url;
    plSpinner.Visible = true;
    Player.controls.play();
}
private void Player_PlayStateChange(int NewState)
{
    if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
    {
        //This never gets executed
        plSpinner.Visible = false;
    }
}

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

如果您试图检测歌曲何时完成,则需要检查WMPPlayState.wmppsMediaEnded