3

是否有可能改变通过 wmplib 播放的 mp3 文件的音量?改变程序本身的音量也可以。

有什么解决方案可以做到这一点吗?

4

3 回答 3

7

这是一种简单的方法。

例子:

WMPlib.WindowsMediaPlayer wmp = new WMPlib.WindowsMediaPlayer(); //Creates an instance of the WMP
wmp.url="URI to media source"; //Sets media source
wmp.settings.volume= 50;  //Volume can be 0-100 (inclusive)

希望对您有所帮助!

于 2013-07-21T00:24:58.140 回答
2

这个想法是发送WM_APPCOMMAND 消息(另见这个答案)。

对于 WPF 使用WindowInteropHelper来获取HandleWindow

class MainWindow : Window
{
    ...

    private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
    private const int WM_APPCOMMAND = 0x319;
    private const int APPCOMMAND_VOLUME_UP = 10 * 65536;
    private const int APPCOMMAND_VOLUME_DOWN = 9 * 65536;

    [DllImport("user32.dll")]
    public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

    private void VolumeUp()
    {
        // APPCOMMAND_VOLUME_UP or APPCOMMAND_VOLUME_DOWN
        var windowInteropHelper = new WindowInteropHelper(this);
        SendMessageW(windowInteropHelper.Handle, (IntPtr)WM_APPCOMMAND, windowInteropHelper.Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
    }
}

对于 Windows 窗体,使用Control.Handle 属性

class MainForm : Form
{
    ...

    private void VolumeUp()
    {
        SendMessageW(Handle, (IntPtr)WM_APPCOMMAND, Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
    }
}
于 2013-01-25T18:45:49.200 回答
0

这对我有用!

WMPLib.WindowsMediaPlayer wmsound= new WMPLib.WindowsMediaPlayer();

wmsound.URL = @"C:\Users\USER\sound.mp3";

//Volume 100%
finish_sound.settings.volume = 100;
于 2014-10-16T19:00:04.667 回答