AW: Get/Set Master Volume Lautstärke?
Zitat:
Anyway - when calling with a False parameter, checking the exact HRESULT it returns FALSE here:
Code:
Windows Version: 10.0 Build 19045, Windows 10 (Version 22H2, OS Build 19045.3570, 64-bit Edition)
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; |
AW: Get/Set Master Volume Lautstärke?
Debugging it further:
Delphi-Quellcode:
When calling SetMasterVolumeMuteState(True);
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; I get these debug messages: TForm1.SetMasterVolumeMuteState: A TForm1.SetMasterVolumeMuteState: B TForm1.SetMasterVolumeMuteState: C TForm1.SetMasterVolumeMuteState: ELSE |
AW: Get/Set Master Volume Lautstärke?
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
I messed that up, but in all cases the master is switching between muted and unmuted with that function, try to capture the R value. Also it seems the behavior is different on my Windows Anhang 56335 As you see in the Log Event first click is OK showing changing state followed by False because the state is not changed. |
AW: Get/Set Master Volume Lautstärke?
Catching the R value on ELSE:
When calling SetMasterVolumeMuteState(True); I get these debug messages: TForm1.SetMasterVolumeMuteState: A TForm1.SetMasterVolumeMuteState: B TForm1.SetMasterVolumeMuteState: C TForm1.SetMasterVolumeMuteState: ELSE = -2147024809 "-2147024809" is "0x80070057," which corresponds to the error code E_INVALIDARG (Invalid arguments). How do you call SetMute? |
AW: Get/Set Master Volume Lautstärke?
Here is my full working example
Code:
procedure TForm10.Button3Click(Sender: TObject);
begin SetMasterMuteState(True); end; procedure TForm10.Button4Click(Sender: TObject); begin SetMasterMuteState(False); end; procedure TForm10.SetMasterMuteState(Muted: Boolean); var MuteStatus: Boolean; FAudioEndpointVolume: AudioEndpoint.IAudioEndpointVolume; // from the Andreas Rejbrand unit FDeviceEnumerator: IMMDeviceEnumerator; FMMDevice: IMMDevice; R: System.HResult; 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 R := FAudioEndpointVolume.SetMute(Muted, nil); case R of S_OK: OutputDebugString('TForm1.SetMasterVolumeMuteState: OK'); // successful operation with a return value of True S_FALSE: OutputDebugString('TForm1.SetMasterVolumeMuteState: FALSE'); // successful operation with a return value of False E_NOINTERFACE: OutputDebugString('TForm1.SetMasterVolumeMuteState: NOINTERFACE'); // Interface not supported E_UNEXPECTED: OutputDebugString('TForm1.SetMasterVolumeMuteState: UNEXPECTED'); // Catastrophic failure E_NOTIMPL: OutputDebugString('TForm1.SetMasterVolumeMuteState: NOTIMPL'); // Operation not implemented else OutputDebugString(PChar('TForm1.SetMasterVolumeMuteState: ELSE '+ IntToHex(R,8))); end; end else begin OutputDebugString('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!'); //CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!'); end; end; |
AW: Get/Set Master Volume Lautstärke?
TForm1.FormKeyUp:
TForm1.SetMasterVolumeMuteState: A TForm1.SetMasterVolumeMuteState: B TForm1.SetMasterVolumeMuteState: C TForm1.SetMasterVolumeMuteState: ELSE 80070057 There must be a difference between our versions of Windows. |
AW: Get/Set Master Volume Lautstärke?
Interesting !
Please try this
Code:
Also did you try to run your application as Administrator ? , it could be some permission problem.
const
IID_IAudioEndpointVolumeEx: TGUID = '{66E11784-F695-4F28-A505-A7080081A78F}'; type IAudioEndpointVolumeEx = interface(IAudioEndpointVolume) [IID_IAudioEndpointVolumeEx] function GetVolumeRangeChannel(nChannel: Integer; out pflVolumeMindB: double; out pflVolumeMaxdB: double; out pflVolumeIncrementdB: double): HRESULT; stdcall; end; procedure TForm10.Button3Click(Sender: TObject); begin SetMasterMuteState(True); end; procedure TForm10.Button4Click(Sender: TObject); begin SetMasterMuteState(False); end; procedure TForm10.SetMasterMuteState(Muted: Boolean); var FAudioEndpointVolumeEx: IAudioEndpointVolumeEx; FDeviceEnumerator: IMMDeviceEnumerator; FMMDevice: IMMDevice; R: System.HResult; 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_IAudioEndpointVolumeEx, CLSCTX_INPROC_SERVER, nil, IAudioEndpointVolume(FAudioEndpointVolumeEx))) then begin OutputDebugString('TForm1.SetMasterVolumeLevelScalar: 3'); //CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 3'); ExitProcess(1); end; if Assigned(FAudioEndpointVolumeEx) then begin R := FAudioEndpointVolumeEx.SetMute(Muted, nil); case R of S_OK: OutputDebugString('TForm1.SetMasterVolumeMuteState: OK'); // successful operation with a return value of True S_FALSE: OutputDebugString('TForm1.SetMasterVolumeMuteState: FALSE'); // successful operation with a return value of False E_NOINTERFACE: OutputDebugString('TForm1.SetMasterVolumeMuteState: NOINTERFACE'); // Interface not supported E_UNEXPECTED: OutputDebugString('TForm1.SetMasterVolumeMuteState: UNEXPECTED'); // Catastrophic failure E_NOTIMPL: OutputDebugString('TForm1.SetMasterVolumeMuteState: NOTIMPL'); // Operation not implemented else OutputDebugString(PChar('TForm1.SetMasterVolumeMuteState: ELSE ' + IntToStr(R))); end; end else begin OutputDebugString('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!'); //CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!'); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:42 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz