i want to adjust the volume programatically like Get/SetMasterVolume in vista and xp? using mmsystem unit?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With