一个计时器中包含2个.wav文件 [英] 2 .wav files in one Timer

查看:76
本文介绍了一个计时器中包含2个.wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在努力进行这项工作,有人可以帮我吗.

我想要的是,当计时器达到275时,应该播放"RedBuffwarning.wav"
并且当它达到299时,应该播放"Redbuff(1).wav"

Hey there im trying to make this work , can someone please help me.

What i want is that when the timer reaches 275 it should play "RedBuffwarning.wav"
And when it reaches 299 it should play "Redbuff(1).wav"

<pre lang="cs">
private void timer5_Tick(object sender, EventArgs e)
     {
         barlizard.Increment(1);
         if (barlizard.Value == 275)
         {
             try
             {
                 var MySoundPlayer1 = new SoundPlayer("sounds\\RedBuffwarning.wav");
                 MySoundPlayer1.Play();
             }
             catch (Exception MyError1)
             {
                 MessageBox.Show("Wrong Somewhere: " + MyError1.Message);
             }
         }
         else
         {
             try
             {
                 var MySoundPlayer = new SoundPlayer("sounds\\RedBuff(1).wav");
                 MySoundPlayer.Play();
                 if (barlizard.Value == 299)
                     barlizard.Value = 0;
                 timer5.Stop();
             }
             catch (Exception MyError)
             {
                 MessageBox.Show("An error has occurred: " + MyError.Message);
             }
         }
     }
     private void buttonlizard_Click(object sender, EventArgs e)
     {
         timer5.Start();
     }


推荐答案

好吧,您似乎在第一个调用时停止了服务器-值将为1,您按下了else块,播放另一波,然后停止计时器.这与您在帖子中提到的不符.

检查值为275,播放第一波.检查299,播放第二波,然后停止计时器.那就是你要做的.

[更新]
----------

为了回应您的评论,这里有一个未经测试的(出于明显的原因)代码片段应该可以完成您想做的事情:

Well you seem to be stopping the server on the first call - Value will be 1, you hit the else-block, play that other wave and then stop the timer. That does not go with what you mentioned in your post.

Check value for 275, play the first wave. Check for 299, play the second wave and then stop the timer. That''s what you need to do there.

[Update]
----------

In response to your comment, here''s an untested (for obvious reasons) code snippet that should do what you are trying to do:

private void timer5_Tick(object sender, EventArgs e)
{
 barlizard.Increment(1);

 if (barlizard.Value == 275)
 {
     try
     {
         var MySoundPlayer1 = new SoundPlayer("sounds\\RedBuffwarning.wav");
         MySoundPlayer1.Play();
     }
     catch (Exception MyError1)
     {
         MessageBox.Show("Wrong Somewhere: " + MyError1.Message);
     }
 }
 else if (barlizard.Value == 299)
 {
     try
     {
         barlizard.Value = 0;
         timer5.Stop();

         var MySoundPlayer = new SoundPlayer("sounds\\RedBuff(1).wav");
         MySoundPlayer.Play();
     }
     catch (Exception MyError)
     {
         MessageBox.Show("An error has occurred: " + MyError.Message);
     }
 }
}


这篇关于一个计时器中包含2个.wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆