Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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));
            }
        }
Beispiel #4
0
 public void Reset()
 {
     AudioSwitchImports.ResetAudioSwitchInstance(LowLevelHandle);
     RebuildRepository();
 }