VolumeControl.Get Method

Gets the current total sound volume.
public float Get()
This language is not supported or no code example is available.

Return Value

float

A float.

public float Get()
 {
     IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator)new MMDeviceEnumerator();
     IMMDevice speakers = null;
     IAudioEndpointVolume vol = null;
     deviceEnumerator.GetDefaultAudioEndpoint(E_DATA_FLOW.eRender,
         E_ROLE.eMultimedia,
         out speakers);
     Guid IID_IAudioEndpointVolume = typeof(IAudioEndpointVolume).GUID;
     speakers.Activate(ref IID_IAudioEndpointVolume, 0,
         IntPtr.Zero,
         out object o);
     vol = (IAudioEndpointVolume)o;
     float currentVolume = 0;
     vol.GetMasterVolumeLevelScalar(out currentVolume);
     if (vol != null)
         Marshal.ReleaseComObject(vol);
     if (speakers != null)
         Marshal.ReleaseComObject(speakers);
     if (deviceEnumerator != null)
         Marshal.ReleaseComObject(deviceEnumerator);
     return currentVolume;
 }
					
This language is not supported or no code example is available.

.NET Framework

Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

.NET Core

Supported in: 5.0+, 6.0+

In this article

Definition