AGB  ·  Datenschutz  ·  Impressum  







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

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.472 Beiträge
 
Delphi 10.4 Sydney
 
#1

AW: Get/Set Master Volume Lautstärke?

  Alt 15. Okt 2023, 15:24
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?
Geändert von PeterPanino, damit der Platz auf dem Bildschirm nicht so leer aussieht.

Geändert von PeterPanino (15. Okt 2023 um 15:39 Uhr)
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
412 Beiträge
 
#2

AW: Get/Set Master Volume Lautstärke?

  Alt 15. Okt 2023, 17:18
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;
Kas
  Mit Zitat antworten Zitat
PeterPanino

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

AW: Get/Set Master Volume Lautstärke?

  Alt 15. Okt 2023, 18:04
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.
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
412 Beiträge
 
#4

AW: Get/Set Master Volume Lautstärke?

  Alt 16. Okt 2023, 08:20
Interesting !

Please try this
Code:
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;
Also did you try to run your application as Administrator ? , it could be some permission problem.
Kas
  Mit Zitat antworten Zitat
Antwort Antwort

 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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:44 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