如何判断主音量是否静音?

发布于 2024-10-10 07:16:58 字数 331 浏览 5 评论 0原文

我正在使用以下方法将计算机上的主音频静音/取消静音。现在,我正在寻找一种确定静音状态的方法。在 C# 中是否有同样简单的方法来做到这一点?

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

I am using the following to mute/unmute the master audio on my computer. Now, I am looking for a way to determine the mute state. Is there a just as easy way to do this in C#?

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〃安静 2024-10-17 07:16:59

查看以下教程。我从未使用过 C#(或任何其他语言)中的 Mixer,因此我假设它们在 P/Invoking Win32 API 中是正确的,并且它们没有重新发明轮子。您可以下载该示例,我认为 GetMixer() 方法可以满足您的需求。

Checkout the following tutorial. I've never played with the Mixer in C# ( or any other language ) so I'm assuming they are correct in P/Invoking the Win32 APIs and that they aren't reinventing the wheel. You can download the example and I think the method GetMixer() will do what you want.

放血 2024-10-17 07:16:59

感谢上面评论中的 RRUZ。请参阅 stackoverflow.com/questions/294292。唯一的问题是你需要兼容模式。

Credit to RRUZ in comments above. See stackoverflow.com/questions/294292. The only problem is that you need compatibility mode.

寒冷纷飞旳雪 2024-10-17 07:16:58

你好,刚刚偶然发现了这个老话题,但我们正在解决完全相同的问题。

我使用以下方法解决了:

using System.Runtime.InteropServices;

...

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);


private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int APPCOMMAND_VOLUME_UP = 0xA0000;
private const int APPCOMMAND_VOLUME_DOWN = 0x90000;               
private const int WM_APPCOMMAND = 0x319;        

...

// mute (toggle)
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);


// unmute
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_DOWN);

静音并不总是使音频静音,它是一个切换 - 但如果您确保首先调用“取消静音”,您应该是黄金。

此致
库尔特

Hi just stumbled accross this old topic, but wa shaving the exact same issue.

I solved using the following:

using System.Runtime.InteropServices;

...

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);


private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int APPCOMMAND_VOLUME_UP = 0xA0000;
private const int APPCOMMAND_VOLUME_DOWN = 0x90000;               
private const int WM_APPCOMMAND = 0x319;        

...

// mute (toggle)
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);


// unmute
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
SendMessage(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_DOWN);

Mute will not always mute the audio, it's a toggle - but if you make sure to call "unmute" first you should be golden.

Best regards
Kurt

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文