VolumeControl.Set Method

Sets the current total sound volume.
public void Set( 
float level 
)
This language is not supported or no code example is available.

Parameters

level
float

The level.

public void Set(float level)
 {
     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;
     vol.SetMasterVolumeLevelScalar(level, Guid.Empty);
     if (vol != null)
         Marshal.ReleaseComObject(vol);
     if (speakers != null)
         Marshal.ReleaseComObject(speakers);
     if (deviceEnumerator != null)
         Marshal.ReleaseComObject(deviceEnumerator);
 }
					
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