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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds