![]() |
Get/Set Master Volume Lautstärke?
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo! Wie kann man in Delphi den Wert der Master Volume Lautstärke erhalten und setzen?
Mein System: Delphi 11 in Windows 10 Anhang 56332 |
AW: Get/Set Master Volume Lautstärke?
Liste der Anhänge anzeigen (Anzahl: 2)
Wenn ich in den Windows Settings den Mixer-Kanal meiner App anzeige, so steht dieser auf 100:
Anhang 56333 Wenn ich dann die JEDI-Komponente TJvSoundControl verwende, kann ich Wave.Volume auf einen Wert einstellen:
Delphi-Quellcode:
Das Setzen dieses Wertes auf 50 (s.o.) stellt den Regler auf 39 ein:
procedure TForm1.FormClick(Sender: TObject);
begin // TJvSoundControl: JvSoundControl1.Wave.Volume := 50; end; Anhang 56334 So weit so gut. Ich möchte aber nicht die Lautstärke meiner App setzen, sondern die allgemeine Lautstärke MASTER VOLUME. Wie kann man das bewerkstelligen? |
AW: Get/Set Master Volume Lautstärke?
Ich habe jetzt endlich eine funktionierende Lösung gefunden, um den Wert von Master Volume (Mute/Unmute, Volume Percent) AUSZULESEN:
Es ist die Lösung von Andreas Rejbrand auf Stack Overflow: ![]() Aber leider weiß ich jetzt noch immer nicht, wie ich den Wert von Master Volume SETZEN kann. Weiß jemand einen Rat? |
AW: Get/Set Master Volume Lautstärke?
Hast Du mal gegoogelt? Bei SO findet sich zumindest dies hier:
![]() |
AW: Get/Set Master Volume Lautstärke?
Ich habe jetzt (mit der AudioEndpoint Unit von Andreas Rejbrand) selbst eine funktionierende Methode gefunden, um den Master Volume Level einzustellen:
Delphi-Quellcode:
Leider wird jedoch der MUTED STATUS nicht unmuted, wenn er vorher muted war!
procedure TForm1.SetMasterVolumeLevelScalar(Level: Single);
var MuteStatus: Boolean; FAudioEndpointVolume: AudioEndpoint.IAudioEndpointVolume; // from the Andreas Rejbrand unit begin //try if not Succeeded(CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, FDeviceEnumerator)) then begin CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 1'); ExitProcess(1); end; if not Succeeded(FDeviceEnumerator.GetDefaultAudioEndpoint(0, 0, FMMDevice)) then begin CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 2'); ExitProcess(1); end; if not Succeeded(FMMDevice.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, nil, FAudioEndpointVolume)) then begin CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 3'); ExitProcess(1); end; if not Succeeded(FAudioEndpointVolume.RegisterControlChangeNotify(Self)) then begin CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: 4'); ExitProcess(1); end; if Assigned(FAudioEndpointVolume) then begin // Get the current mute status FAudioEndpointVolume.GetMute(MuteStatus); // Unmute if it was muted: if MuteStatus then FAudioEndpointVolume.SetMute(False, nil); // This line is executed, but the master volume is NOT unmuted! // Ensure the level is within the valid range (0.0 to 1.0): Level := Max(0.0, Min(1.0, Level)); // Set the master volume level as a scalar: FAudioEndpointVolume.SetMasterVolumeLevelScalar(Level, nil); // it works! // Optionally, you can send a notification or update your UI here end else begin CodeSite.Send('TForm1.SetMasterVolumeLevelScalar: FAudioEndpointVolume not assigned!'); end; {except on E: Exception do begin // Handle any exceptions here CodeSite.Send('Exception in SetMasterVolumeLevelScalar', E.Message); end; end;} end; Weiß jemand, wie man diesen Fehler beheben kann? |
AW: Get/Set Master Volume Lautstärke?
My two cents on this, Mute and Enable are intentionally undocumented by Microsoft, these will compromise the user privacy, like .. by simply enabling the disabled microphone in first place, or just unmute the speakers without the user consent and play some audio.
It is doable and it is not a hack, but unethical to share, so you have to ask the user himself to enable (eg. the Mic) or unmute the speakers. |
AW: Get/Set Master Volume Lautstärke?
Zitat:
|
AW: Get/Set Master Volume Lautstärke?
gefunden...
Code:
uses MMSystem;
... procedure GetWaveVolume(var volL, volR: DWord); var hWO: HWAVEOUT; waveF: TWAVEFORMATEX; vol: DWORD; begin volL:= 0; volR:= 0; // init TWAVEFORMATEX FillChar(waveF, SizeOf(waveF), 0); // open WaveMapper = std output of playsound waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0); // get volume waveOutGetVolume(hWO, @vol); volL:= vol and $FFFF; volR:= vol shr 16; waveOutClose(hWO); end; procedure SetWaveVolume(const volL, volR: DWord); var hWO: HWAVEOUT; waveF: TWAVEFORMATEX; vol: DWORD; begin // init TWAVEFORMATEX FillChar(waveF, SizeOf(waveF), 0); // open WaveMapper = std output of playsound waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0); vol:= volL + volR shl 16; // set volume waveOutSetVolume(hWO, vol); waveOutClose(hWO); end; |
AW: Get/Set Master Volume Lautstärke?
Zitat:
Kannst du in Settings -> App volume and device preferences genau beobachten. Danke jedenfalls für deinen Beitrag! Much appreciated! |
AW: Get/Set Master Volume Lautstärke?
Zitat:
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:
It is working on my Windows 10 (1803)
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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz