There are 3 songs in the program, how to make the next one play on completion of one music file, and so on until the program finishes its work.

private void enter_Click(object sender, EventArgs e)// Вход { SoundPlayer splay = new SoundPlayer(@"c:\music.play_.wav"); splay.Play(); string[] file = DownloadFileFromServer("http://", "members"); for (int i = 0; i < file.Length; i++) { if (enter_login.Text == file[i]&& enter_password.Text==file[i+1]) { chat_panel.Visible = true; login_text.Text = enter_login.Text; password_text.Text = enter_password.Text; nickname = enter_login.Text; } } if (chat_panel.Visible == false) MessageBox.Show("Неверный логин или пароль"); }к 
  • Give your code: with what music is played. - Alexander Petrov
  • The SoundPlayer class is what? Windows Media Player or something else? - BlackWitcher 2:49 PM
  • System.Media this is ZOOM SMASH
  • It seems to me, here is one of the answers to your question: msdn.microsoft.com/en-us/library/tbx06asw(v=vs.110).aspx - BlackWitcher

1 answer 1

You can play audio files synchronously, in an infinite loop, in a separate stream (task).

 Task.Factory.StartNew(() => { // Здесь загрузка ваших файлов var files = new string[] { @"C:\Windows\Media\Alarm01.wav", @"C:\Windows\Media\Alarm02.wav", @"C:\Windows\Media\Alarm03.wav" }; var player = new SoundPlayer(); while (true) { foreach (var file in files) { player.SoundLocation = file; player.PlaySync(); } } }, TaskCreationOptions.LongRunning); 

Pay attention to the LongRunning option - it is desirable to specify it, since the task will be performed for a long time.

  • But there is a kind of asynchronous mode of the player, if I do not confuse anything. - BlackWitcher
  • @BlackWitcher - There are asynchronous. But there is no track playback end event. So how to include the following composition? Is that to destroy the player after each track and the event Disposed create a new one. IMHO, it's harder. - Alexander Petrov
  • And there he has a state, so you need to watch it. Stackowerflow in English is an example . - BlackWitcher
  • @BlackWitcher - There's an example for MediaPlayer . Here we are talking about the primitive SoundPlayer , which only plays wav-files. - Alexander Petrov
  • It is guilty, indeed, so. And about a separate task, you have already given an answer, which has been added for a long time. - BlackWitcher