Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can I play an mp3 song straight after the previous mp3 song has finished? I've checked everywhere but they aren't detailed enough. I'm using WMPLib. How can I change this code so that I can play another song straight after the previous song has come to an end.
C#
#region Playing Music
private void button1_Click(object sender, EventArgs e)
{
    musicplayer.URL = @"C:\Users\User\Documents\Music\Song1.mp3";
    musicplayer.controls.play();
}
#endregion
Posted
Updated 18-Jul-15 10:39am
v2
Comments
[no name] 18-Jul-15 17:24pm    
https://msdn.microsoft.com/en-us/library/windows/desktop/dd562692(v=vs.85).aspx
Coder1999 19-Jul-15 5:57am    
I'm doing it in c# not c++
[no name] 19-Jul-15 12:03pm    
So what? Then use C#. If you have actually looked at the documentation. you would have seen C# example code.

hi,
try this code. its working i have tested
include windows media player library before using the below code
C#
		{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Audio Files (.mp3)|*.mp3";
if(dialog.ShowDialog() == DialogResult.OK)
{
    string path = dialog.FileName;
    playSound(path);
    WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = path;
wplayer.controls.play();
}
 
Share this answer
 
v2
Comments
Coder1999 19-Jul-15 5:53am    
I have seen that before but it didn't help.
Something like this should do the Job:

C#
...
WindowsMediaPlayer musicplayer = new WindowsMediaPlayer();
// Add Event handler
musicplayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(MusicPlayer_StatusChange);
...


C#
// The eventhandler
private void MusicPlayer_StatusChange(int NewState)
{
    if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
    {
       // Start next
    }
}


Note:
I think with WindowsMediaPlayer's PlayList you can solve it mutch more elegant.

[EDIT]
http://stackoverflow.com/questions/14063843/how-to-add-multiple-files-to-a-playlist[^]
 
Share this answer
 
v2
Comments
Coder1999 19-Jul-15 9:38am    
What do you put where it says //start new
[no name] 19-Jul-15 10:02am    
// Next filename, of course not fixed programmed, should come from a list
musicplayer.URL = @"C:\Users\User\Documents\Music\Song2.mp3";
// Play
musicplayer.controls.play();

So the same you have in your button click.
Coder1999 19-Jul-15 10:25am    
Ok. But then all the songs will play at the same time won't they?
[no name] 19-Jul-15 10:33am    
You need to implement a list of strings from where you take the next song.

musicplayer.URL = myPlayList[listIndex++];

and course you Need to check that "listIndex" is in the range.
Coder1999 19-Jul-15 10:55am    
Wouldn't it be easier if i made a string for each song then list all the string variables into the musicplayer.ToString and then add a loop after that.

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