Ejemplo n.º 1
0
        private void ChangeDevice()
        {
            int             c;
            CoreAudioDevice CAD;

            string[] fav = GetDeviceList();

            ChargeDevicesList();

            if (lstDevices.CheckedItems.Count == 0)
            {
                return;
            }

            if (lstDevices.CheckedItems.Count == 1)
            {
                CAD = (CoreAudioDevice)lstDevices.CheckedItems[0];
                if (!CAD.IsDefaultDevice)
                {
                    if (fav.Contains(CAD.Id.ToString()))
                    {
                        if (Controller.SetDefaultDevice(CAD))
                        {
                            DefaultAudioDevice   = CAD;
                            txtActualDevice.Text = DefaultAudioDevice.FullName;
                            ShowNotification("Default device now is: " + DefaultAudioDevice.FullName);
                        }
                    }
                }
                return;
            }

            for (c = index; c < lstDevices.CheckedItems.Count; c++)
            {
                CAD = (CoreAudioDevice)lstDevices.CheckedItems[c];
                if (!CAD.IsDefaultDevice)
                {
                    if (fav.Contains(CAD.Id.ToString()))
                    {
                        if (Controller.SetDefaultDevice(CAD))
                        {
                            DefaultAudioDevice   = CAD;
                            txtActualDevice.Text = DefaultAudioDevice.FullName;
                            index = c;
                            ShowNotification("Default device now is: " + DefaultAudioDevice.FullName);
                            return;
                        }
                    }
                }

                if (c + 1 == lstDevices.CheckedItems.Count)
                {
                    c = -1;
                }
            }
        }
Ejemplo n.º 2
0
        public IHttpContext SetSound(IHttpContext context)
        {
            if (Authentication.Enabled)
            {
                HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity;
                if (!Authentication.VerifyAuthentication(identity))
                {
                    context.Response.SendResponse(JsonConvert.SerializeObject(Authentication.FailedAuthentication)); return(context);
                }
            }

            ResponseMessage Response = new ResponseMessage();

            Response.Message    = "Please input correct id or name. Get id by using /getid";
            Response.Successful = false;

            var enc = Encoding.GetEncoding(context.Request.ContentEncoding.CodePage);
            var id  = Encoding.UTF8.GetString(enc.GetBytes(context.Request.QueryString["id"])) ?? JsonConvert.SerializeObject(Response);

            CoreAudioController controller = new CoreAudioController();
            var devices = controller.GetPlaybackDevices();

            foreach (CoreAudioDevice device in devices)
            {
                if (device.RealId == id)
                {
                    controller.SetDefaultDevice(device);
                    Response.Message    = $"Switched to audio device: {device.FullName}";
                    Response.Successful = true;
                }
                if (device.FullName == id && device.State == AudioSwitcher.AudioApi.DeviceState.Active)
                {
                    try
                    {
                        controller.SetDefaultDevice(device);
                        Response.Message    = $"Switched to audio device: {device.FullName}";
                        Response.Successful = true;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            controller.Dispose();
            context.Response.ContentEncoding = Encoding.Default;
            context.Response.SendResponse(JsonConvert.SerializeObject(Response));
            return(context);
        }
        static void ProcessTimer(object source, ElapsedEventArgs e)
        {
            Guid deviceId = (Guid)Properties.Settings.Default["DeviceId"];
            int  found    = FindWindow("CUIEngineWin32", "Steam");

            if (found != 0 && !(audioSwitched))
            {
                Console.WriteLine("Big Picture!");
                audioSwitched = true;
                CoreAudioDevice newDevice = audio.GetDevice(deviceId);

                audio.SetDefaultDevice(newDevice);
            }
            else if (found == 0 && audioSwitched)
            {
                audioSwitched = false;

                audio.SetDefaultDevice(startDevice);
            }
        }
Ejemplo n.º 4
0
        public static bool SetDeviceByName(this CoreAudioController controller, string idOrName)
        {
            Console.WriteLine("Setting device...");
            var device = controller.GetDeviceByName(idOrName);

            if (device == null)
            {
                Console.WriteLine($"Failed to set device, could not find device with Id or Name {idOrName}");
                return(false);
            }

            if (!controller.SetDefaultDevice(device))
            {
                Console.WriteLine($"Failed to set device");
                return(false);
            }

            Console.WriteLine($"{device.DeviceType} device set to {device.InterfaceName}|{device.Name}");
            return(true);
        }
 public bool SetDefaultDevice(CoreAudioDevice device)
 {
     return(coreAudioController.SetDefaultDevice(device));
 }