.NET Framework - c# media player problem

Asked By Tonci on 28-Dec-11 03:58 AM
Hello everyone,

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
AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(axPlayer_PlayStateChange);
string myPlaylist = "moja_zadnja"; // playlist name
//WMPLib.IWMPPlaylist pl;
WMPLib.IWMPPlaylistArray plItems;
plItems = axPlayer.playlistCollection.getByName(myPlaylist);

//pl = plItems.Item(0);
if (plItems.count == 0)
{
// MessageBox.Show("COUNT = 0");
pl = axPlayer.playlistCollection.newPlaylist(myPlaylist);
}
else
{
//MessageBox.Show("COUNT != 0");
pl = plItems.Item(0);
}
axPlayer.settings.autoStart = true; //not necessary
axPlayer.currentPlaylist = pl; //Set media player to use
the playlist.
axPlayer.Ctlcontrols.play(); // start playing
}

private void axPlayer_PlayStateChange(object sender,
AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8)//Media stopped
{
// state 8 occurs when going to next song so I used that
IWMPMedia trenutni_medij =
axPlayer.currentPlaylist.Item[0]; // current media
axPlayer.currentPlaylist.removeItem(trenutni_medij);
// 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)
{

axPlayer.Ctlcontrols.play();
// 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.

}

MSDN here
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562460%28v=vs.85%29.aspx
states:


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
order."

Now, I am confused what to do.

Thank you and best wishes for holidays.




}




Peter Duniho replied to Tonci on 28-Dec-11 12:43 PM
The main problem at the moment is that you are posting to the wrong
newsgroup/forum.  This newsgroup is for questions about the C# language,
and occasionally .NET features.  COM/ActiveX controls such as the
Windows Media Player are outside the scope of the newsgroup and outside
the expertise of most if not all of us.  You'll get much better advice
if you find a place to ask your question where it is on-topic.

Just guessing about your question based on the code and comments you
posted: probably you need to look at more information than just the
that item is in fact the one that is no longer playing.

But that is just a wild guess.  You really need to ask your question
where you are actually likely to find someone who knows exactly what
you are asking about.

Pete
Tonci replied to Peter Duniho on 28-Dec-11 02:44 PM
Thank you very much Pete for advice, next time I will be more careful.

Just finished programming session that lasted for more than 4 hours. I
find a way to do it, without playlists, working with regular files :).

Works great.

Best regards from Croatia,

Tonci Buljan