Einzelnen Beitrag anzeigen

PeterPanino

Registriert seit: 4. Sep 2004
1.451 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: Get/Set Master Volume Lautstärke?

  Alt 15. Okt 2023, 13:06
The user should always be in control of his computer's sound!
Sure but Windows lack ability to do permissions like iOS or Android so they revert to prohibit some API without explicitly user inatraction.

I was mistaken with the mute status, my old project was on specific request from a client where he wanted to control the devices in Sound Control Panel to enable and disable a device and change the Default device for both Playback and Recording, which is not allowed without user interaction, it took me hours of debugging to extract the Windows internal code which was one freaking line!!

Anyway i tried this based on your code and it is working just fine
Code:
...
    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)))
...
It is working on my Windows 10 (1803)
Isn't the logic inverted here? (if not Succeeded -> SetMute OK)

Anyway - when calling with a False parameter, checking the exact HRESULT it returns FALSE here:
Code:
    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
    end;
Windows Version: 10.0 Build 19045, Windows 10 (Version 22H2, OS Build 19045.3570, 64-bit Edition)
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.

Geändert von PeterPanino (15. Okt 2023 um 13:41 Uhr)
  Mit Zitat antworten Zitat