SystemSounds仅播放一种声音

时间:2019-01-21 17:23:19

标签: c#

所以我正在使用使用最新的c#框架的win表格应用程序。

这里我有一个播放声音(星号)的按钮,然后在5秒钟或20秒钟后(我让用户选择),我希望它播放不同的声音(在这种情况下为哔声),但是当它调用代码时发出哔的声音,我听到的是星号。

最后,我想要另一个声音来表示它已经结束。我选择了(感叹号),但我再次听到星号。

有人知道为什么我只会听到一个声音吗?

P.S。我尝试将开始声音切换为哔声,将“下一个”声音切换为星号。我清理并重建,但是然后听到的唯一声音是哔声。

这是按钮单击的代码

 private void btnStart_Click(object sender, EventArgs e)
            {
                BusinessLayer.ToneApp.PlaySound play = new BusinessLayer.ToneApp.PlaySound();

                _countDown = play.IsValid(txtTime.Text);
                numreps = play.IsValid(txtReps.Text);
                numsets = play.IsValid(txtSets.Text);

                lblFinished.Text = "";


                play.PlaySoundStart();
                _timer = new System.Windows.Forms.Timer();
                _timer.Enabled = true;
                _timer.Tick += new EventHandler(timer1_Tick);
                _timer.Interval = 1000;
                _timer.Start();

            }

在timer1_tick事件中我有

private void timer1_Tick(object sender, EventArgs e)
        {
            BusinessLayer.ToneApp.PlaySound play = new BusinessLayer.ToneApp.PlaySound();

            _countDown--;
            if (_countDown < 1)
            {
//my code
                play.PlaySoundNext();
}
}

最后是我的演奏声

    public class PlaySound
    {
        public void PlaySoundStart()
        {
            System.Media.SystemSounds.Asterisk.Play();

        }

        public void PlaySoundNext()
        {
            System.Media.SystemSounds.Beep.Play();

        }

        public void PlaySoundStop()
        {
            System.Media.SystemSounds.Exclamation.Play();

        }



        public int IsValid(string textToInt)
        {
            int.TryParse(textToInt, out int timeInSeconds);

            return timeInSeconds;
        }

    }

1 个答案:

答案 0 :(得分:-1)

您不应期望SystemSounds有任何特定的声音,因为用户可以更改它们。呼叫BeepAsterisk发出信号或引起更多注意。我认为Hand的意思是表示事件突然停止或以异常方式停止。有一个broader answer与此相关,它还指出了将自己的系统声音添加到Windows中的可能性。

在Windows的最新版本中,AsteriskBeepExclamation的默认声音似乎都是相同的。我在Windows 10版本1909上进行了检查。Hand不同,Question完全没有声音。我猜是这样写的,因为前三个不能互换使用,原因是不清楚何时合适使用它们。 Question声音可能已被删除,因为即使没有声音,带有问题的提示也很烦人。

自定义声音

您可以将自己的声音嵌入到应用程序中。为此,您可以签出System.Media.SoundPlayer。可以使用Assembly.GetManifestResourceStream加载嵌入式资源。另外,可以将声音文件添加到资源文件,并通过自动生成的类进行访问。

相关问题