Einzelnen Beitrag anzeigen

PeterPanino

Registriert seit: 4. Sep 2004
1.465 Beiträge
 
Delphi 10.4 Sydney
 
#12

AW: Get/Set Master Volume Lautstärke?

  Alt 15. Okt 2023, 14:43
Debugging it further:

Delphi-Quellcode:
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;
When calling SetMasterVolumeMuteState(True);

I get these debug messages:

TForm1.SetMasterVolumeMuteState: A
TForm1.SetMasterVolumeMuteState: B
TForm1.SetMasterVolumeMuteState: C
TForm1.SetMasterVolumeMuteState: ELSE
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.
  Mit Zitat antworten Zitat