我怎么知道visual c#中的Windows Media Player控件何时播放完一首歌?

时间:2011-08-02 18:19:39

标签: c# visual-studio-2005 windows-media-player

我只需要知道媒体播放器播放歌曲的时间,是否有旗帜或其他内容......

3 个答案:

答案 0 :(得分:3)

根据MSDN,您应该可以使用PlayStateChanged事件。该活动为AxWMPLib._WMPOCXEvents_PlayStateChangeEvent

请参阅枚举参考here。您似乎可以使用wmppsMediaEnded找出媒体流何时结束。

答案 1 :(得分:1)

我认为这在VB.net中提供了一个示例,也许您可​​以根据自己的需要对其进行调整:http://msdn.microsoft.com/en-us/library/dd562692(v=vs.85).aspx

编辑:刚刚注意到VB示例下面有一个c#解决方案。

答案 2 :(得分:1)

检查playstateChanged事件Here

的代码实现
// Add a delegate for the PlayStateChange event.
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);

private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    // Test the current state of the player and display a message for each state.
    switch (e.newState)
    {
        case 0:    // Undefined
            currentStateLabel.Text = "Undefined";
            break;

    case 1:    // Stopped
        currentStateLabel.Text = "Stopped";
        break;

    case 2:    // Paused
        currentStateLabel.Text = "Paused";
        break;

    case 3:    // Playing
        currentStateLabel.Text = "Playing";
        break;

    case 4:    // ScanForward
        currentStateLabel.Text = "ScanForward";
        break;

    case 5:    // ScanReverse
        currentStateLabel.Text = "ScanReverse";
        break;

    case 6:    // Buffering
        currentStateLabel.Text = "Buffering";
        break;

    case 7:    // Waiting
        currentStateLabel.Text = "Waiting";
        break;

    case 8:    // MediaEnded
        currentStateLabel.Text = "MediaEnded";
        break;

    case 9:    // Transitioning
        currentStateLabel.Text = "Transitioning";
        break;

    case 10:   // Ready
        currentStateLabel.Text = "Ready";
        break;

    case 11:   // Reconnecting
        currentStateLabel.Text = "Reconnecting";
        break;

    case 12:   // Last
        currentStateLabel.Text = "Last";
        break;

    default:
        currentStateLabel.Text = ("Unknown State: " + e.newState.ToString());
        break;
}

}