logo
VitNX3 Documentation

# VolumeControl.Get Method

Namespace: VitNX3.Functions.WinControllers
Assembly: VitNX3 (in VitNX3.dll)
Gets the current total sound volume.
VB
C#
F#
C++
JScript
Copy

    public float Get()

    This language is not supported or no code example is available.

#### Return Value

float

A float.

Source code
VB
C#
F#
C++
JScript
Copy

    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.

Applies to

#### .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+
See Also
VolumeControl Class
VitNX3.Functions.WinControllers Namespace