Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!!

I want to play multiple audio file from a folder, but I only play the first file
This is my code :

C#
List<string> wavlist = new List<string>();
wavlist.Add(Application.StartupPath + "\\mp3\\1.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\2.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\3.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\4.mp3");

foreach (string file in wavlist)
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = file;
wplayer.control.play();
}


Please help me!
@_@
Thanks and best regards.
Posted
Comments
sreeyush sudhakaran 8-Oct-15 2:27am    
with in the loop wait for something like this?
foreach (string file in wavlist)
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = file;
wplayer.control.play();
while(wplayer.control.status == Playing)
{
//Dummy loop
}
}

1 solution

You can create a playlist and use that to play files sequentially. Here is sample code to do so:

C#
WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("NewPlaylist");

// Add files to playlist. You can make use of a loop to add multiple files
WMPLib.IWMPMedia fileMedia = player.newMedia(filePath);
playlist.appendItem(fileMedia);

player.currentPlaylist = playlist;
player.Ctlcontrols.play();


Another approach will be to use PlayStateChanged event handler.
 
Share this answer
 
Comments
Robinson Niit 8-Oct-15 8:40am    
Thanks d@nish, if I try your solution, how can I get the name of the playing file in the playlist? Thanks and best regards
Member 14920876 2-Sep-20 13:43pm    
what is the player actually

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900