문제
관리되는 .net 코드에서 볼륨을 설정하는 쉬운 방법이 있습니까?
해결책
이 긴 기사는 다음과 같은 방법을 보여줍니다. C#의 사운드 볼륨 제어
다른 팁
이것은 내 Windows 7을 위해 수행합니다.
naudio (http://naudio.codeplex.com/releases/view/79035)를 다운로드하고 프로젝트에서 DLL을 참조하십시오. 다음 코드를 추가하는 것보다 :
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
{
//Set at maximum volume
dev.AudioEndpointVolume.MasterVolumeLevel = 0;
//Get its audio volume
System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString());
//Mute it
dev.AudioEndpointVolume.Mute = true;
System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted");
}
catch (Exception ex)
{
//Do something with exception when an audio endpoint could not be muted
System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted");
}
}
}
catch (Exception ex)
{
//When something happend that prevent us to iterate through the devices
System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message);
}
이 CodeProject 기사 시스템의 마스터 볼륨을 포함하여 Windows 믹서 설정을 완전히 제어하는 방법을 보여줍니다.이는 끔찍한 Win API 항목의 대부분을 포함하는 것으로 보이므로 아마도 가장 쉬운 방법일 것입니다.
간단한 답변 : Interop을 사용해야합니다.
나는 당신을 위해 모든 종류의 소리를하기 위해 도서관을 썼습니다.
winnmm.net : http://winmm.codeplex.com/
제휴하지 않습니다 StackOverflow