AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Get/Set Master Volume Lautstärke?
Thema durchsuchen
Ansicht
Themen-Optionen

Get/Set Master Volume Lautstärke?

Ein Thema von PeterPanino · begonnen am 14. Okt 2023 · letzter Beitrag vom 16. Okt 2023
Antwort Antwort
PeterPanino

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

Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 09:10
Hallo! Wie kann man in Delphi den Wert der Master Volume Lautstärke erhalten und setzen?

Mein System: Delphi 11 in Windows 10

volume.png
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.

Geändert von PeterPanino (14. Okt 2023 um 09:29 Uhr)
  Mit Zitat antworten Zitat
PeterPanino

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

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 10:31
Wenn ich in den Windows Settings den Mixer-Kanal meiner App anzeige, so steht dieser auf 100:

Initial.png

Wenn ich dann die JEDI-Komponente TJvSoundControl verwende, kann ich Wave.Volume auf einen Wert einstellen:

Delphi-Quellcode:
procedure TForm1.FormClick(Sender: TObject);
begin
  // TJvSoundControl:
  JvSoundControl1.Wave.Volume := 50;
end;
Das Setzen dieses Wertes auf 50 (s.o.) stellt den Regler auf 39 ein:

setvolume.png

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?
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.
  Mit Zitat antworten Zitat
PeterPanino

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

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 11:57
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:

https://stackoverflow.com/questions/...on-mute-unmute

Aber leider weiß ich jetzt noch immer nicht, wie ich den Wert von Master Volume SETZEN kann. Weiß jemand einen Rat?
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.
  Mit Zitat antworten Zitat
Benutzerbild von Sherlock
Sherlock

Registriert seit: 10. Jan 2006
Ort: Offenbach
3.765 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 12:04
Hast Du mal gegoogelt? Bei SO findet sich zumindest dies hier: https://stackoverflow.com/questions/...e-in-windows-7 Keine Ahnung inwieweit das mittlerweile in irgendwelchen MS API Units gekapselt sein könnte.
Oliver
Geändert von Sherlock (Morgen um 16:78 Uhr) Grund: Weil ich es kann
  Mit Zitat antworten Zitat
PeterPanino

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

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 13:57
Ich habe jetzt (mit der AudioEndpoint Unit von Andreas Rejbrand) selbst eine funktionierende Methode gefunden, um den Master Volume Level einzustellen:

Delphi-Quellcode:
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;
Leider wird jedoch der MUTED STATUS nicht unmuted, wenn er vorher muted war!

Weiß jemand, wie man diesen Fehler beheben kann?
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
227 Beiträge
 
#6

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 16:05
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.
  Mit Zitat antworten Zitat
PeterPanino

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

AW: Get/Set Master Volume Lautstärke?

  Alt 14. Okt 2023, 17:56
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.
In fact, that's what I am planning: The user should be able to simply click a button on my app to quickly mute or unmute his master volume without having to awkwardly call the Windows settings each time. With my apps, I always strive to make the operation of Windows easier, which is often unnecessarily complicated on many advanced settings. One usage example is: quickly switching off the sound while annoying commercials are playing in a movie. The user should always be in control of his computer's sound!
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.

Geändert von PeterPanino (14. Okt 2023 um 17:58 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:47 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