Skip to content

Instantly share code, notes, and snippets.

@hisasann
Last active October 22, 2017 05:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/afd734e688893df345e05185864b5345 to your computer and use it in GitHub Desktop.
Save hisasann/afd734e688893df345e05185864b5345 to your computer and use it in GitHub Desktop.
windows上でボリュームを変更するコード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreAudioApi;
namespace DeviceManager.Volume
{
class VolumeController
{
public void SetVolume(int value)
{
// via http://moguriblogg.blogspot.jp/2017/01/c25.html
//音量を変更
MMDevice device;
MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
device.AudioEndpointVolume.MasterVolumeLevelScalar = ((float)value / 100.0f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment