0

I have a part in my WinForms program that opens a second form with animation in a PictureBox and starts playing music through SoundPlayer. The problem is that after 0.5 seconds from the start of music playback, a loud white noise appears, music is not heard at all. Here is the code from this part:

private void timer1_Tick(object sender, EventArgs e)
{
    i += 1;
    progressBar1.Value = i;
    
    if(i == 99)
    {
        timer1.Enabled = false;
        SoundPlayer sp = new SoundPlayer(Properties.Resources.notsoimportant);
        sp.Play();
        MessageBox.Show("notsoimportant");
        label1.Text = "notsoimportant";
        button1.Text = "notsoimportant";
        timer2.Enabled = true;
        a = true;
        SoundPlayer sp1 = new SoundPlayer(Properties.Resources.notsoimportant2);
        sp1.Play();
        Form2 f2 = new Form2();
    }
}
private void timer2_Tick(object sender, EventArgs e)
{
    i -= 1;
    progressBar1.Value = i;
    
    if (i == 0)
    {
        timer2.Enabled = false;
        MessageBox.Show("notsoimportant");
    }
}

It is enough to just declare the form, and it happens. As I said, the second form has 1 timer and 1 PictureBox. All it does is render the GIF in full screen with switch case. If I remove Form2 f2 = new Form2 ();, then there will be no white noise.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
V1PEX7
  • 1
  • provide [Minimal, Complete, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Specifically, provide `form2` constructor scope code snippet. Also, clarify in your question when there is no white noise are the sounds playing\working as expected? – Brett Caswell Sep 24 '20 at 22:30
  • Nobody will get a repro for this. Try another machine, shop for a better audio driver. And don't ask it to be smart by itself, never call Play() when the previous sound hasn't finished yet. – Hans Passant Sep 24 '20 at 22:37
  • Does it make a difference if you play your sound in a different thread?... – Idle_Mind Sep 24 '20 at 23:13

0 Answers0