// If the RecordingVolume parameter received a value public static void SetRecordingVolume(int volumeAsPercentage) { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); // Set the volume level of the default recording device to that of the float value received by the RecordingVolume parameter DevEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia).AudioEndpointVolume.MasterVolumeLevelScalar = volumeAsPercentage / 100.0f; }
public static void SetRecordingMute(bool muteState) { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); // Set the mute state of the default recording device to that of the boolean value received by the Cmdlet DevEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia).AudioEndpointVolume.Mute = muteState; }
// If the RecordingMuteToggle paramter was called public static void RecordingMuteToggle() { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); // Toggle the mute state of the default recording device DevEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia).AudioEndpointVolume.Mute = !DevEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia).AudioEndpointVolume.Mute; }
public static AudioDevice SetById(string id) { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); // For every MMDevice in DeviceCollection for (int i = 0; i < DeviceCollection.Count; i++) { // If this MMDevice's ID is the same as the string received by the ID parameter if (string.Compare(DeviceCollection[i].ID, id, System.StringComparison.CurrentCultureIgnoreCase) == 0) { // Create a new audio PolicyConfigClient PolicyConfigClient client = new PolicyConfigClient(); // Using PolicyConfigClient, set the given device as the default communication device (for its type) client.SetDefaultEndpoint(DeviceCollection[i].ID, ERole.eCommunications); // Using PolicyConfigClient, set the given device as the default device (for its type) client.SetDefaultEndpoint(DeviceCollection[i].ID, ERole.eMultimedia); // Output the result of the creation of a new AudioDevice while assining it the index, and the MMDevice itself, and a default value of true return(new AudioDevice(i + 1, DeviceCollection[i], true)); } } // Throw an exception about the received ID not being found throw new System.ArgumentException("No enabled AudioDevice found with that ID"); }
public static AudioDevice SetByInputObject(AudioDevice inputObject) { if (inputObject == null) { throw new ArgumentNullException(nameof(inputObject)); } var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); for (int i = 0; i < DeviceCollection.Count; i++) { var tempDevice = DeviceCollection[i]; // If this MMDevice's ID is the same as the ID of the MMDevice received by the InputObject parameter if (DeviceCollection[i].ID == inputObject.ID) { // Create a new audio PolicyConfigClient PolicyConfigClient client = new PolicyConfigClient(); // Using PolicyConfigClient, set the given device as the default playback communication device client.SetDefaultEndpoint(DeviceCollection[i].ID, ERole.eCommunications); // Using PolicyConfigClient, set the given device as the default playback device client.SetDefaultEndpoint(DeviceCollection[i].ID, ERole.eMultimedia); // Output the result of the creation of a new AudioDevice while assining it the an index, and the MMDevice itself, and a default value of true return(new AudioDevice(i + 1, DeviceCollection[i], true)); } } // Throw an exception about the received device not being found throw new System.ArgumentException("No such enabled AudioDevice found"); }
public static AudioDevice SetByIndex(int index) { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); // If the Index is valid if (index >= 1 && index <= DeviceCollection.Count) { // Create a new audio PolicyConfigClient PolicyConfigClient client = new PolicyConfigClient(); // Using PolicyConfigClient, set the given device as the default communication device (for its type) client.SetDefaultEndpoint(DeviceCollection[index - 1].ID, ERole.eCommunications); // Using PolicyConfigClient, set the given device as the default device (for its type) client.SetDefaultEndpoint(DeviceCollection[index - 1].ID, ERole.eMultimedia); // Output the result of the creation of a new AudioDevice while assining it the index, and the MMDevice itself, and a default value of true return(new AudioDevice(index, DeviceCollection[index - 1], true)); } else { // Throw an exception about the received Index not being found throw new System.ArgumentException("No enabled AudioDevice found with that Index"); } }
public static void SetPlaybackVolume(float volumeAsPercentage) { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).AudioEndpointVolume.MasterVolumeLevelScalar = volumeAsPercentage / 100.0f; }
public static void PlaybackMuteToggle() { var(DevEnum, DeviceCollection) = GetAudioDevice.GetDeviceCollection(); DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).AudioEndpointVolume.Mute = !DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).AudioEndpointVolume.Mute; }