首页 > 解决方案 > 当我尝试在 C# WinForms 中打开第二个表单时,声音播放器中出现白噪声

问题描述

我在我的 WinForms 程序中有一个部分,它在 PictureBox 中打开带有动画的第二个表单,并开始通过 SoundPlayer 播放音乐。问题是音乐播放开始0.5秒后,出现很大的白噪音,根本听不到音乐。这是这部分的代码:

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");
    }
}

只需声明表单就足够了,它会发生。正如我所说,第二种形式有 1 个计时器和 1 个 PictureBox。它所做的只是用开关盒全屏渲染 GIF。如果我删除Form2 f2 = new Form2 ();,则不会有白噪声。

标签: c#winformssoundplayer

解决方案


推荐阅读