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

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Today's competitive marketplace requires the organization to frequently release and deploy applications at the pace of user demands, with reduced cost, risk, and increased quality. This book defines the basics of application release and deployment, and provides best practices for implementation with resources for a deeper dive. Inside you will find: The business and technical drivers behind automated application release and deployment. Evaluation guides for application release and deployment solutions. …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds