procedure TForm10.SetMasterMuteState(Muted: Boolean);
var
MuteStatus: Boolean;
FAudioEndpointVolume: AudioEndpoint.IAudioEndpointVolume; // from the Andreas Rejbrand
unit
FDeviceEnumerator: IMMDeviceEnumerator;
FMMDevice: IMMDevice;
begin
if not Succeeded(CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_INPROC_SERVER,
IID_IMMDeviceEnumerator, FDeviceEnumerator)) then
begin
OutputDebugString('TForm1.SetMasterVolumeLevelScalar: 1');
//CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 1');
ExitProcess(1);
end;
if not Succeeded(FDeviceEnumerator.GetDefaultAudioEndpoint(0, 0, FMMDevice)) then
begin
OutputDebugString('TForm1.SetMasterVolumeLevelScalar: 2');
//CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 2');
ExitProcess(1);
end;
if not Succeeded(FMMDevice.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, nil,
FAudioEndpointVolume)) then
begin
OutputDebugString('TForm1.SetMasterVolumeLevelScalar: 3');
//CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 3');
ExitProcess(1);
end;
if Assigned(FAudioEndpointVolume) then
begin
if not Succeeded(FAudioEndpointVolume.SetMute(Muted, nil)) then
OutputDebugString(PChar('TForm1.SetMasterVolumeLevelScalar: SetMute OK ' + BoolToStr
(Muted, True)))
else
OutputDebugString(PChar('TForm1.SetMasterVolumeLevelScalar: SetMute Fail ' +
BoolToStr(Muted, True)))
end
else
begin
OutputDebugString('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!');
//CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!');
end;
end;