public void SetDefaultAudioDevice(AudioDevice audioDevice)
        {
            if (!Repository.Exists(audioDevice))
            {
                throw new AudioSwitchWrapperException("The audio device " + audioDevice + " is not present in the local repository. The repository must be refreshed before continuing.");
            }

            long result = AudioSwitchImports.SetDefaultAudioPlaybackDevice(LowLevelHandle, audioDevice.ID);
        }
        public AudioDevice GetDefaultAudioDevice()
        {
            byte [] buffer = new byte[500];
            int     len    = 0;

            AudioSwitchImports.GetDefaultAudioPlaybackDeviceId(LowLevelHandle, buffer, 500, out len);
            string defaultInstanceId = System.Text.Encoding.UTF8.GetString(buffer, 0, len);

            AudioDevice ret = Repository.GetById(defaultInstanceId);

            if (ret == null)
            {
                Reset();
                return(GetDefaultAudioDevice());
            }

            return(ret);
        }
        private void RebuildRepository()
        {
            Repository.Flush();

            int nDevices = 0;

            AudioSwitchImports.GetAudioPlaybackDevicesCount(LowLevelHandle, out nDevices);

            for (int i = 0; i < nDevices; i++)
            {
                byte [] buffer = new byte[500];
                int     len;

                AudioSwitchImports.GetAudioPlaybackDeviceProperty(LowLevelHandle, i, 1, buffer, 500, out len);
                string deviceId = System.Text.Encoding.UTF8.GetString(buffer, 0, len);

                AudioSwitchImports.GetAudioPlaybackDeviceProperty(LowLevelHandle, i, 2, buffer, 500, out len);
                string deviceName = System.Text.Encoding.UTF8.GetString(buffer, 0, len);

                Repository.Add(new AudioDevice(deviceId, deviceName));
            }
        }
 public void Reset()
 {
     AudioSwitchImports.ResetAudioSwitchInstance(LowLevelHandle);
     RebuildRepository();
 }