procedure TForm1.SetMasterVolumeMuteState(Muted: Boolean);
var
MuteStatus: Boolean;
FAudioEndpointVolume: AudioEndpoint.IAudioEndpointVolume;
// from the Andreas Rejbrand unit
FDeviceEnumerator: IMMDeviceEnumerator;
FMMDevice: IMMDevice;
begin
CodeSite.Send('
TForm1.SetMasterVolumeMuteState: A');
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;
CodeSite.Send('
TForm1.SetMasterVolumeMuteState: B');
if Assigned(FAudioEndpointVolume)
then
begin
CodeSite.Send('
TForm1.SetMasterVolumeMuteState: C');
var R: System.HResult := FAudioEndpointVolume.SetMute(Muted,
nil);
case R
of
S_OK: CodeSite.Send('
TForm1.SetMasterVolumeMuteState: OK');
// successful operation with a return value of True
S_FALSE: CodeSite.Send('
TForm1.SetMasterVolumeMuteState: FALSE');
// successful operation with a return value of False
E_NOINTERFACE: CodeSite.Send('
TForm1.SetMasterVolumeMuteState: NOINTERFACE');
// Interface not supported
E_UNEXPECTED: CodeSite.Send('
TForm1.SetMasterVolumeMuteState: UNEXPECTED');
// Catastrophic failure
E_NOTIMPL: CodeSite.Send('
TForm1.SetMasterVolumeMuteState: NOTIMPL');
// Operation not implemented
else CodeSite.Send('
TForm1.SetMasterVolumeMuteState: ELSE');
end;
end
else
begin
//OutputDebugString('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!');
CodeSite.Send('
TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!');
end;
end;