none
Is the command to check if the bell is running or stopped ? RRS feed

  • Question

  • I have the following C # statement:
    ...
    using (SoundPlayer player = new SoundPlayer(Properties.Resources.ring))
    {
    player.Play();
      //What should I write here? 
      while (If the bell is running, wait here)
      {
          if (player.Stop()==true)
          {
              this.progressBarControl1.Visible = false; //false = không cho phép hiện
          }
      }
    }
    ... 

     

    I want to check if the ringer is running or stopping, if it is running then wait until it stops before running this.progressBarControl1.Visible = false.


    Friday, November 8, 2019 8:00 AM

All replies

  • You can use mciSendString with status command

    (tested on Windows 10)

    Friday, November 8, 2019 10:48 AM
  • Try PlaySync instead of Play. It will play and wait.

    Friday, November 8, 2019 11:08 AM
  • hi Castorix31!

    I do not know how to use "mciSendString with status command" do you have an example ?

    Hi Viorel !

    method "PlaySync" does not check the status "ON / OFF" when the bell rings, you see my code.

    public Form1()
            {
                InitializeComponent();
                lblStatusPlaySound.ForeColor = Color.Violet;
                lblStatusPlaySound.Text = "Status: OFF/ON";
            }
            private void btnPlaySound_Click(object sender, EventArgs e)
            {
                lblStatusPlaySound.ForeColor = Color.Green;
                lblStatusPlaySound.Text = "Status: ON";
    
                using (SoundPlayer player = new SoundPlayer(Properties.Resources.ring))
                {
                    player.PlaySync();
                }
    
                lblStatusPlaySound.ForeColor = Color.Red;
                lblStatusPlaySound.Text = "Status: OFF";
            }

    Monday, November 11, 2019 10:01 AM
  • If you mean that the label is not changed immediately, then try executing ‘lblStatusPlaySound.Update( )’ after setting the colour and text, before starting the player.

    Monday, November 11, 2019 10:45 AM
  • Now I understand, thank you
    Tuesday, November 12, 2019 9:16 AM
  • Hi lamtriendong,
    I am glad you have got your solution. We appreciated you shared us your solution. And we also hope you can mark it as an answer. By marking a post as Answered, you help others find the answer faster.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 21, 2020 8:47 AM