C# get master volume level/precent

后端 未结 3 1012
余生分开走
余生分开走 2020-12-10 06:29

I got this code to mute/unmute the master volume

private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;

[DllImport(\"u         


        
相关标签:
3条回答
  • 2020-12-10 06:49

    I could not do it for all Windows versions (xp, vista & 7).
    Though, I achieved it by used external programs, such as NirCmd, and sent the command I needed.

    not so good solution but it did solve my problem.

    0 讨论(0)
  • 2020-12-10 07:01

    This thread shows how to control the master volume from C#.

    You might also be interested in the responses to this question: Get Master Sound Volume in c#

    Especially the NAudio managed wrapper.

    0 讨论(0)
  • 2020-12-10 07:03

    Have a look at this project http://www.codeproject.com/KB/vista/CoreAudio.aspx

    They created an own mixer control, that also reports the current volumne and the mute/unmute state:

    defaultDevice.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(
        AudioEndpointVolume_OnVolumeNotification);
    // .. snip ..
    void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
    {
        Console.WriteLine("New Volume {0}", data.MasterVolume);
        Console.WriteLine("Muted      {0}", data.Muted);
    }
    

    Does this help you?

    EDIT: With this code and the class from the project you should be able to set and unset mute directly (without toggle):

    MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
    MMDevice defaultDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
    defaultDevice.AudioEndpointVolume.Mute = true; // or false
    
    0 讨论(0)
提交回复
热议问题