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

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds