-6
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?

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459

1 Answers1

2

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();
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • how to generate random number in between. So, that the player should play random songs.Is it possible?. If possible then please provide me the code... – user2499953 Jun 28 '13 at 03:48