c# media player problem


T

Tonci

Hello everyone,

I'm 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 doesn't 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(v=vs.85).aspx
states:

"Remarks

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'm confused what to do.

Thank you and best wishes for holidays.




}
 
Ad

Advertisements

T

Tonci

[...]
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 doesn't play second, then plays
third and since then, everything is ok.

}
[...]

Now, I'm confused what to do.

The main problem at the moment is that you're 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's 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
"newState" value, so that you only remove an item from the playlist when
that item is in fact the one that is no longer playing.

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

Pete


Thank you very much Pete for advice, next time I'll 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top