Search code examples
c#windows-media-player

All songs are starting simultaneously instead of one after another


WindowsMediaPlayer[] player = new WindowsMediaPlayer[31];

for(int i = 1; i < 30 ; i++ )
{
    player[i] = new WindowsMediaPlayer();
    player[i].URL = @"C://Songs//m" + i + ".mp3";
    player[i].controls.play();
}

here I am using array to store the url and to play. but all the songs are starting at one time instead of one after another.How to solve this problem?


Solution

  • The problem is, that you create multiple instances of the control and let them all play one song. You should just create one instance add all songs to the "CurrentPlaylist" and then let the control play it:

    WindowsMediaPlayer player = new WindowsMediaPlayer;
    
            for (int i = 1; i < 30; i++)
            {
                IWMPMedia media = player.newMedia( @"C://Songs//m" + i + ".mp3");
                player.currentPlaylist.appendItem(media);                
            }
    
            player.controls.play();