-2

How can I get the speaker volume in C#?

speaker volume image

And show it in my app?

App image

DiplomacyNotWar
  • 31,605
  • 6
  • 57
  • 75

1 Answers1

1

Using NAudio, you could do the following:

using NAudio.CoreAudioApi;
.....
//  download NAudio.dll from https://github.com/naudio/NAudio/releases
//  and add it as Reference to the project

var devEnum = new MMDeviceEnumerator();
var defaultDevice = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
var volume = defaultDevice.AudioEndpointVolume;
float leftVolumePercent = volume.Channels[0].VolumeLevelScalar * 100;
float rightVolumePercent = volume.Channels[1].VolumeLevelScalar * 100;
float masterVolumePercent = volume.MasterVolumeLevelScalar * 100;

This article demonstrates, how to achieve such things without external frameworks.

Axel Kemper
  • 8,984
  • 2
  • 29
  • 50