Change mp3 playback volume via wmplib in c #
How can I change the volume of an mp3 file that is played through wmplib? Changing the volume of the program itself would be nice.
Are there any solutions for this?
+3
f4bzen
source
to share
3 answers
The idea is to send a WM_APPCOMMAND message (also see this answer ),
For WPF, use WindowInteropHelper to get Handle
Window
:
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);
}
}
For Windows Forms use the Control.Handle Property :
class MainForm : Form
{
...
private void VolumeUp()
{
SendMessageW(Handle, (IntPtr)WM_APPCOMMAND, Handle, (IntPtr)APPCOMMAND_VOLUME_UP);
}
}
+2
Sergey Brunov
source
to share
This is an easy way to do it.
Example:
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)
Hope this helped you!
+8
Abid Ali
source
to share
It worked for me!
WMPLib.WindowsMediaPlayer wmsound= new WMPLib.WindowsMediaPlayer();
wmsound.URL = @"C:\Users\USER\sound.mp3";
//Volume 100%
finish_sound.settings.volume = 100;
0
Philipp88
source
to share