SoundPlayer.play方法应用问题

.Net技术 码拜 9年前 (2015-04-02) 1543次浏览 0个评论

用SoundPlayer类 然后写的下面这个代码,为什么只有b这个能发出声音,a发不出声音(a、b单独都能播放出来)

private void button1_Click(object sender, EventArgs e)
        {
            
           
                   SoundPlayer a = new SoundPlayer(Properties.Resources.a);
                   a.Play();
              
                   SoundPlayer b = new SoundPlayer(Properties.Resources.b);
                   b.Play();
             

        }
换成这个也不行。。。。
private void button1_Click(object sender, EventArgs e)
        {
            
           for(int m=0;m<2;m++)
           {
               if (m == 0)
               {
                   SoundPlayer a = new SoundPlayer(Properties.Resources.a);
                   a.Play();
               }
               if (m == 1)
               {
                   SoundPlayer b = new SoundPlayer(Properties.Resources.b);
                   b.Play();
               }

           }
        }

SoundPlayer.play方法应用问题
40分
如果a、b单独都可以发出声音,那么你在a、b发生之间,加一个Thread.Sleep(3000)
a、b的声音你就可以都听到了

SoundPlayer a = new SoundPlayer(Properties.Resources.a);
                    a.Play();

Thread.Sleep(3000);

                    SoundPlayer b = new SoundPlayer(Properties.Resources.b);
                    b.Play();
SoundPlayer.play方法应用问题
我加了一个using System.Threading;然后把Thread.Sleep(3000);放在a、b中间,发现还是只有b发音,a没有声音,然后我又在a前面加了一个Thread.Sleep(100);然后两个都就能发出声音了,谢谢

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明SoundPlayer.play方法应用问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!