Tip: C# - Detect the End of Media - axWindowsMediaPlayer

I saw too many articles regarding how to detect the end of a song using axWindowsMediaPlayer.

A lot of people say you have to watch the axWindowsMediaPlayer.status until it actually becomes "Stopped".

That is wrong...

Why? What if the user presses the Stop button for your application? It returns "Stopped" too, so that won't work.

axWindowsMediaPlayer.EndOfStream is still not good. But some people think it is.

The trick is to use the axWindowsMediaPlayer.PlayStateChanged().

Basically, this will let you monitor every single state of your axWindowsMediaPlayer control.
Here is a list of all the states.

0 = Undefined
1 = Stopped (by User)
2 = Paused
3 = Playing
4 = Scan Forward
5 = Scan Backwards
6 = Buffering
7 = Waiting
8 = Media Ended
9 = Transitioning
10 = Ready
11 = Reconnecting
12 = Last

So, from that list you should know that you must use 8.

In the event we will do the following:

private void axWindowsMediaPlayer1_PlayStateChange(
    object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) {
    if (e.newState == 8) {
        //Your Code Here
    }
}

That's basically it.

Hope this helps a lot of people, but most importantly YOU The Reader!

ClayC


About the Author

Clayton Coleiro

Welcome to my profile, I am ClayC. I came on these forums to maybe get some feedback on my applications and maybe even help some people out with some stuff they need help with. I have been using C# for over a year now, I also code in php, css, html, javascript, C# and VB (that's what I started on :P) Anyways if you got any questions, then feel free to message me ;)

Comments

  • can I detect End of a playlist

    Posted by darkni8 on 09/12/2011 08:59am

    Hi,thnx for this helpful post. n specifically for mentioning that stopped(by user).But can I detect end of a playlist in AXWINDOWMEDIAPLAYER....

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds