管理された.netコードからボリュームを設定する簡単な方法はありますか?
6859 次
4 に答える
4
これは私のWindows7でそれを行います:
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);
}
于 2012-09-21T16:42:09.587 に答える
3
このかなり長い記事は、次の方法を示しています。C#での音量の制御
于 2009-05-27T12:30:52.503 に答える
1
このCodeProjectの記事では、システムのマスターボリュームを含め、Windowsミキサーの設定を完全に制御する方法について説明します。恐ろしいWinAPIのもののほとんどをラップしているように見えるので、おそらく最も簡単な方法です。
于 2009-05-27T12:33:53.230 に答える
1
簡単な答え:相互運用機能を使用する必要があります。
私はあなたのためにあらゆる種類のサウンドを行うためのライブラリを作成しました。
WinnMM.Net:http://winmm.codeplex.com/ _
于 2009-05-27T12:34:15.007 に答える