Пример #1
0
 private void toggleMuteButton_Click(object sender, EventArgs e)
 {
     try
     {
         microphone.ToggleMute();
         setProgressBar();
         setTrayIcon();
     }
     catch (Exception ex) { MessageBox.Show($"The following error occurred when trying to toggle mute.\n\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
     try
     {
         if (microphone.IsMuted && Settings.Default.PlaySound)
         {
             muteSound.Play();
         }
         else if (!microphone.IsMuted && Settings.Default.PlaySound)
         {
             unmuteSound.Play();
         }
     }
     catch (Exception ex) { MessageBox.Show($"The following error occurred when trying to play a sound file.\n\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading config...");
            Config config = Init.GetConfig();

            Pin = Init.GeneratePIN(config.PinLength);

            Console.WriteLine("***********");
            Console.WriteLine("PIN: {0}", Pin);
            Console.WriteLine("***********");

            Console.WriteLine("Connecting audio device...");
            CoreAudioDevice audioDevice = (new CoreAudioController()).DefaultPlaybackDevice;

            WebSocket ws = new WebSocket(config.HostName);

            ws.OnOpen += (sender, e) =>
            {
                Console.WriteLine("Connected");
            };

            ws.OnMessage += (sender, e) =>
            {
                string[] data = e.Data.Split('\n');
                if (data.Length != 2)
                {
                    ws.Send("UNVALID");
                    return;
                }

                string senderPin = data[0];
                string command   = data[1];

                if (senderPin != Pin)
                {
                    ws.Send("UNAUTHORIZED");
                    return;
                }

                Console.WriteLine(command);

                switch (command)
                {
                case "VOLUP":
                    audioDevice.Volume += 2; break;

                case "VOLDOWN":
                    audioDevice.Volume -= 2; break;

                case "MUTE":
                    audioDevice.ToggleMute(); break;

                case "PREVIOUS":
                    keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); break;

                case "PAUSE":
                    keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); break;

                case "NEXT":
                    keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); break;
                }

                Console.Write("> ");
            };

            ws.OnError += (sender, e) =>
            {
                Console.WriteLine("ERROR {0}", e.Message);
            };

            Console.WriteLine("Connecting to server...");
            ws.Connect();

            string cliCommand = "";

            do
            {
                Console.Write("> ");
                cliCommand = Console.ReadLine();

                if (cliCommand == "reset")
                {
                    Pin = Init.GeneratePIN(config.PinLength);
                    Console.WriteLine("New PIN: {0}", Pin);
                }
                else if (cliCommand == "setpin")
                {
                    Console.Write("Custom PIN: ");
                    Pin = Console.ReadLine();

                    Console.WriteLine("New PIN: {0}", Pin);
                }
                else if (cliCommand == "reconfig")
                {
                    System.IO.File.Delete("remocon.conf");
                    config = Init.GetConfig();
                }
                else if (cliCommand != "exit")
                {
                    Console.WriteLine("Unvalid command");
                }
            }while (cliCommand != "exit");
        }
Пример #3
0
 public void Mute()
 {
     Sound.ToggleMute();
 }