在C#中控制音量在Windows中使用WMPLib [英] Controlling volume in C# using WMPLib in Windows

查看:511
本文介绍了在C#中控制音量在Windows中使用WMPLib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故事:
我写的语音控制音乐播放器。此前该项目用于音乐Winamp的 - 我想弄死它。我想用音乐播放器,语音控制集成。现在的问题是,改变了我的媒体播放器对象的体积属性时(mplayer.settings.volume = 5),它改变了主卷。而音乐播放含义任何声音的反馈将完全听不到。当你驾驶不冷静。如果我火了Windows媒体播放器,我可以改变音乐的音量,而不会影响主音量..所以,必须有一种方式。



我想过可能的找出是否有埋藏在那里的均衡器控制,但该文件是可悲的。 - 如果不是这样,我的谷歌富薄弱



因此​​,没有人知道我怎么会去分离主音量的音乐与Windows Media Player控制。

情况:
目标机器是XP(SP3),与.NET 4.0,我相信。此外,这是一个控制台应用程序。



在此先感谢您的帮助。


解决方案

只有我这样发现这样做的是使用互操作和窗口WM_APPCOMMAND消息:

 私人const int的APPCOMMAND_VOLUME_MUTE = 0x80000; 
私人const int的WM_APPCOMMAND = 0x319;
私人const int的APPCOMMAND_MICROPHONE_VOLUME_UP = 26 * 65536;
私人const int的APPCOMMAND_MICROPHONE_VOLUME_DOWN = 25 * 65536;

函数[DllImport(user32.dll中)]
公共静态外部的IntPtr SendMessageW(IntPtr的的HWND,诠释消息,IntPtr的的wParam,lParam的IntPtr的);
私人无效SetMicVolume()
{
SendMessageW(新WindowInteropHelper(本).Handle,WM_APPCOMMAND,新(IntPtr的)APPCOMMAND_MICROPHONE_VOLUME_UP); //或_down
}


The story: I'm writing a music player controlled by voice. Previously the project used winamp for music -- which I'd like to do away with. I'd like to integrate the voice control with music player. The problem is, when changing the volume property of my media player object (mplayer.settings.volume = 5;), it changes the MASTER volume. Meaning any voice feedback will be completely inaudible while music is playing. Not cool when you're driving. If I fire up windows media player, I can change the volume of the music without affecting the master volume.. so there has to be a way.

I've thought of maybe finding out if there's an equalizer control buried in there, but the documentation on that is pathetic. -- either that or my google-fu is weak.

So does anyone know how I would go about separating master and music volume with windows media player control?

Particulars: Target machine is XP(sp3), with .NET 4.0 I believe. Also, this is a console app.

Thanks in advance for any help

解决方案

The only way I found of doing this was using Interop and WM_APPCOMMAND windows message:

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    private const int APPCOMMAND_MICROPHONE_VOLUME_UP = 26 * 65536;
    private const int APPCOMMAND_MICROPHONE_VOLUME_DOWN = 25 * 65536;

    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
    private void SetMicVolume()
    {
        SendMessageW(new WindowInteropHelper(this).Handle, WM_APPCOMMAND, new (IntPtr)APPCOMMAND_MICROPHONE_VOLUME_UP);//or _DOWN
    }

这篇关于在C#中控制音量在Windows中使用WMPLib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆