【问题标题】:How can I know when a Windows Media Player control in visual c# has finished of playing a song?我如何知道 Visual c# 中的 Windows Media Player 控件何时播放完歌曲?
【发布时间】:2011-10-18 12:04:21
【问题描述】:

我只需要知道媒体播放器何时播放完歌曲,是否有标志或其他东西......

【问题讨论】:

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


【解决方案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;
}

}

【讨论】:

    【解决方案2】:

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

    参见枚举参考here。看来您可以使用wmppsMediaEnded 来了解媒体流何时结束。

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多