3

I just need to know when the media player finishes of playing a song, if there is a flag or something...

luigi007
  • 63
  • 2
  • 4
  • I don't know anything about media player but I assume there's an event that gets fired. You should look into that. – Kevin Aug 02 '11 at 18:23
  • Use the PlayStateChange event: http://msdn.microsoft.com/en-us/library/dd562460%28VS.85%29.aspx – Hans Passant Aug 02 '11 at 18:31

3 Answers3

3

According to MSDN, you should be able to use the PlayStateChanged event. The event is AxWMPLib._WMPOCXEvents_PlayStateChangeEvent

See the enumeration reference here . It seems that you can use wmppsMediaEnded to find out when the media stream has ended.

Bryan Crosby
  • 6,486
  • 3
  • 36
  • 55
1

Check code implementation of playstateChanged event 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;
}

}

Avinash
  • 140
  • 1
  • 2
  • 7
1

I think this gives an example in VB.net, maybe you can adapt it for your purpose: http://msdn.microsoft.com/en-us/library/dd562692(v=vs.85).aspx

EDIT: Just noticed there's a c# solution below the VB example.

Kevin
  • 24,871
  • 19
  • 102
  • 158