Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to adjust master volume in vista/xp

i want to adjust the volume programatically like Get/SetMasterVolume in vista and xp? using mmsystem unit?

like image 902
XBasic3000 Avatar asked Aug 09 '10 02:08

XBasic3000


People also ask

How do you adjust master volume?

Click the Start button, and then click Control Panel. In the Control Panel window, click Hardware and Sound. In the Hardware and Sound window, under Sound, click Adjust system volume. In the Volume Mixer window, in the Device box, click and drag the slider up to increase or down to decrease the volume.

How do I adjust volume in Windows 7?

1. To adjust the output volume, click the speaker icon on the lower right corner of the Taskbar. Change the volume by moving the slider.


1 Answers

Here's the implementation of a general purpose api for audio: MMDevApi

http://social.msdn.microsoft.com/Forums/en/windowspro-audiodevelopment/thread/5ce74d5d-2b1e-4ca9-a8c9-2e27eb9ec058

and an example with a button

unit Unit33;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MMDevApi, ActiveX, StdCtrls;

type
  TForm33 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form33: TForm33;
  endpointVolume: IAudioEndpointVolume = nil;

implementation

{$R *.dfm}


procedure TForm33.Button1Click(Sender: TObject);
var
  VolumeLevel: Single;
begin
  if endpointVolume = nil then Exit;
  VolumeLevel := 0.50;
  endpointVolume.SetMasterVolumeLevelScalar(VolumeLevel, nil);
  Caption := Format('%1.8f', [VolumeLevel])
end;

procedure TForm33.FormCreate(Sender: TObject);
var
  deviceEnumerator: IMMDeviceEnumerator;
  defaultDevice: IMMDevice;
begin
  CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, deviceEnumerator);
  deviceEnumerator.GetDefaultAudioEndpoint(eRender, eConsole, defaultDevice);
  defaultDevice.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, nil, endpointVolume);
end;

end.
like image 180
Sebastian Oliva Avatar answered Sep 19 '22 21:09

Sebastian Oliva