Search code examples
c#.netaudiowmplib

c# Detecting when a music file has stopped playing in the WMPLib


I need to know when a music file has stopped playing to play the next song in a playlist string array I made.

I use the WMPLib and here is my code to get the song playing:

https://gyazo.com/993d8ea2dff20316f6c98ff88ab57394 + under a button event I usePlayFile(@playlist[0]);`

Also I realised I have a memory leak so if someone just happened to also know the code for fixing that for every song that would be cool.


Solution

  • One solution would be to give Windows Media Player the whole playlist at once, so you don't have to worry about that. Refer to How to add multiple files to a playlist. On the other hand, you already subscribed to the PlayStateChange event. https://msdn.microsoft.com/en-us/library/windows/desktop/dd562460%28v=vs.85%29.aspx describes all the possible states, and I'm sure on of these PlayStateChanges is the right one for you. Maybe MediaEnded?