5

私は C# と WPF を学んでいて、ちょっとしたユーティリティのアイデアがありました。すべての Windows サウンド (システム ビープ音、WMP、DVD プレーヤーなど) を完全にミュート/ミュート解除する VS 2008 でオブジェクト ブラウザーを調べましたが、できません私が必要としているものを見つけたようです: すべての Windows に影響するミュート。

それはそれでSystem.Windows.Input.MediaCommands.MuteVolumeあり、私はそれを使用する方法を理解していませんか?

C# や WPF を使用して正しい方向へのポインタをありがとう。:)

4

2 に答える 2

6

I'm pretty sure that command is used by the individual WPF controls for muting. For instance, if the CommandTarget were a MediaElement, it would mute its sound when that command was executed. Unfortunately, I think you're going to have to do a bit more work. A quick google gave some examples for doing the p/invoke way, which is probably the only way to do it as of now in .NET:

For XP: MSDN

For Vista/7: CodeProject

于 2010-02-28T14:46:32.770 に答える
1

NAudio (http://naudio.codeplex.com/releases/view/79035) を使用できます。最新バージョンをダウンロードします。DLL を抽出し、C# プロジェクトで DLL NAudio を参照します。

次に、次のコードを追加して、使用可能なすべてのオーディオ デバイスを反復処理し、可能であればミュートします。

        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
        }
于 2012-09-21T16:22:55.110 に答える