FiFiWiki2

FiFiWikiの第2版

ユーザ用ツール

サイト用ツール


c.sharp:windowsボリュームを操作

C#を使用してWindowsボリュームをミュート

https://code.i-harness.com/ja/q/259e9

snippet.cpp
try
    {
        //Instantiate an Enumerator to find audio devices
        NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
        //Get all the devices, no matter what condition or status
        NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
        //Loop through all devices
        foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
        {
            try
            {
                //Show us the human understandable name of the device
                System.Diagnostics.Debug.Print(dev.FriendlyName);
                //Mute it
                dev.AudioEndpointVolume.Mute = true;
            }
            catch (Exception ex)
            {
                //Do something with exception when an audio endpoint could not be muted
            }
        }
    }
    catch (Exception ex)
    {
        //When something happend that prevent us to iterate through the devices
    }
c.sharp/windowsボリュームを操作.txt · 最終更新: 2018/04/21 12:08 by fifi