How to get Speaker Volume Level? [duplicate]

一曲冷凌霜 提交于 2020-01-07 17:49:51

问题


How can I get the speaker volume in C#?

speaker volume image

And show it in my app?

App image


回答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.



来源:https://stackoverflow.com/questions/51925520/how-to-get-speaker-volume-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!