Reputation: 288
I have a listbox that contains all media files that has to be played. How do make media player play 1 by one? This code plays 1 song but foreach is supposed to play all files, but I quess that is because it doesn't wait till media ended.. this code:
Listbox = listBox3
listBox3Dict[s]
= string for all files in listbox
Dictionary<string, string> listBox3Dict = new Dictionary<string, string>();
> private bool listbox3job()
> {
> AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
> {
> foreach (var selected in listBox3.Items)
> {
> string s = selected.ToString();
>
> if (listBox3Dict.ContainsKey(s))
> {
WMPLib.IWMPPlaylist playlist = axWindowsMediaPlayer1.newPlaylist("myPlaylist", string.Empty);
// you can add songs to url on for loop
WMPLib.IWMPMedia temp = this.axWindowsMediaPlayer1.newMedia(listBox3Dict[s]); //Load media from URL.
playlist.appendItem(temp); //Add song to playlist.
// after you add all songs set the new playlist
this.axWindowsMediaPlayer1.settings.autoStart = true; //not necessary
this.axWindowsMediaPlayer1.currentPlaylist = playlist; //Set media player to use the playlist.
> }
> }
>
> return true;
> }
> return false;
> }
Upvotes: 1
Views: 6750
Reputation: 63065
what you can do is create player list and start play that list
private bool listbox3job()
{
AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
WMPLib.IWMPPlaylist playlist = axWmp.newPlaylist("myPlaylist", string.Empty);
foreach (var selected in listBox1.Items)
{
string s = selected.ToString();
if (listBox3Dict.ContainsKey(s))
{
WMPLib.IWMPMedia temp = axWmp.newMedia(listBox3Dict[s]); //Load media from URL.
playlist.appendItem(temp); //Add song to playlist.
}
}
axWmp.settings.autoStart = true; //not necessary
axWmp.currentPlaylist = playlist; //Set media player to use the playlist.
return true;
}
http://www.timwylie.com/playlist.html
Upvotes: 3
Reputation: 418
Earlier I was working on a set of speech files in a list. I used PlayStateChange event. From this event you can find MediaEnded state where you can reassign the playfile to next item in the list.
Upvotes: 0