I am writing small c# media player app. Situation is like this:
I want it to read playlist from file (works great).
I want it to remove song once that song is finished playing (I have
problems with this one).
My code is here:
private void Form1_Load(object sender, EventArgs e)
axPlayer.PlayStateChange += new
string myPlaylist = "moja_zadnja"; // playlist name
plItems = axPlayer.playlistCollection.getByName(myPlaylist);
//pl = plItems.Item(0);
if (plItems.count == 0)
// MessageBox.Show("COUNT = 0");
pl = axPlayer.playlistCollection.newPlaylist(myPlaylist);
//MessageBox.Show("COUNT != 0");
pl = plItems.Item(0);
axPlayer.settings.autoStart = true; //not necessary
axPlayer.currentPlaylist = pl; //Set media player to use
axPlayer.Ctlcontrols.play(); // start playing
private void axPlayer_PlayStateChange(object sender,
if (e.newState == 8)//Media stopped
// state 8 occurs when going to next song so I used that
IWMPMedia trenutni_medij =
axPlayer.currentPlaylist.Item; // current media
// problem is that state 8 occurst when removing media, so situation
is like this, it plays first song, then does not play second, then plays
third and since then, everything is ok.
else if (e.newState == 1)
// I put this here because when first song is played, // mediaplayer
stops (goes to state 1)
//downside of this else if is that it replays last song. But when I
remove else if (e.newState == 1) then mediaplayer stops after first song.
Windows Media Player states are not guaranteed to occur in any
particular order. Furthermore, not every state necessarily occurs during
a sequence of events. You should not write code that relies upon state
Now, I am confused what to do.
Thank you and best wishes for holidays.