AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Projekte TAudioVolume Komponente incl. System Mixer
Thema durchsuchen
Ansicht
Themen-Optionen

TAudioVolume Komponente incl. System Mixer

Ein Thema von EWeiss · begonnen am 6. Mai 2018 · letzter Beitrag vom 24. Jul 2019
Antwort Antwort
EWeiss
(Gast)

n/a Beiträge
 
#1

AW: TAudioVolume Komponente incl. System Mixer

  Alt 9. Mai 2018, 18:12
Habe den Quelltext jetzt nicht vor mir, aber ich habe in dem Beispielformular den oben genannten Eventhändler definiert und jeder tempSessionDingsbums an OnSessionCreated rangetackert. Bei neuen Programm mit Audioausgabe, z.B. FooBar2000, wurde das Event mehrfach ausgelöst. Also der Teil wo das Postmessage machst.
OK dann habe ich einen Denkfehler.
Muss dann wohl über AudioVolume1 doch das Event initialisieren.
Bin da wohl selbst über den Session und MasterVolumen Kram gestolpert.

Trotzdem bekomme ich kein Event..
Kann es sein das dieses nur von Anwendungen ausgelöst wird die das Interface auch unterstützen?
Denn wenn ich einen meiner Player starte passiert da gar nichts. Der Mixer selbst erkennt ihn aber und addiert ihn als Session.

Delphi-Quellcode:
{ TSessionNotification }

function TAudioSessionNotification.OnSessionCreated(const NewSession: IAudioSessionControl): HResult;
begin
  PostMessage(MsgHandle, WM_SessionCreate, integer(@NewSession), 0);

  Result := S_OK;
end;
Hier passiert nix.

Danke..

Zitat:
Hast du mal überlegt die IAudioSessionEvents, IMMNotificationClient, IAudioSessionNotification und IAudioEndpointVolumeCallback in TAudioVolume zu integrieren?
Mir ist jetzt nicht ganz klar wie du das bewerkstelligen würdest.
Bin mit dem VCL Kram nicht gerade sehr bewandert.
Zitat:

Zitat:
Hm...die anderen Icons von den Anwendungen leaken auch...versuch mal, ob du das schöner hinkriegst.
Mache ich.. Danke

gruss

Geändert von EWeiss ( 9. Mai 2018 um 18:38 Uhr)
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.079 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: TAudioVolume Komponente incl. System Mixer

  Alt 9. Mai 2018, 18:56
Vom Smartphone schreiben ist schwierig, aber du kannst das machen:

TAudioVolume = class(TWinControl, IAudioSessionEvents, IMMNotificationClient, IAudioSessionNotification, IAudioEndpointVolumeCallback) Dann halt wie gehabt die notwendigen Methoden hinzufügen.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#3

AW: TAudioVolume Komponente incl. System Mixer

  Alt 9. Mai 2018, 19:01
Vom Smartphone schreiben ist schwierig, aber du kannst das machen:

TAudioVolume = class(TWinControl, IAudioSessionEvents, IMMNotificationClient, IAudioSessionNotification, IAudioEndpointVolumeCallback) Dann halt wie gehabt die notwendigen Methoden hinzufügen.
OK werde mal versuchen es umzusetzen.
Danke.

EDIT:
Schwierig.
Habe ja schon 2 x TAudioVolume

Delphi-Quellcode:
  TAudioVolume = class; // <<<<<
  TSplitStrArray = array of string;

  // ByMyAction is used to check if this event is triggered by self action, i.e., my application's
  // execution of SetMasterMute, SetMasterVolume, SetSysSoundMute or SetSysSoundVolume.
  TOnMasterVolumeEvent = procedure(ByMyAction: boolean; Volume: single; Mute: boolean) of object;
  TOnSessionVolumeEvent = procedure(ByMyAction: boolean; Volume: single; Mute: boolean) of object;
  TOnSessionStateEvent = procedure(Sender: TAudioVolume; NewState: integer) of object;
  TOnSessionDisconnected = procedure(Sender: TAudioVolume; DisconnectReason: uint) of object;
  TOnDeviceStateChange = procedure(DeviceId: string; NewDeviceState: DWORD) of object;
  TOnDefaultDeviceChange = procedure(NewDefaultDevice: TDeviceInfo) of object;
  TOnSessionCreated = procedure(NewSession: IAudioSessionControl) of object;

  TAudioVolume = class(TWinControl)// <<<<<<
Das
TAudioVolume = class(TWinControl)
zu ändern nach
TAudioVolume = class(TWinControl, IAudioSessionEvents, IMMNotificationClient, IAudioSessionNotification, IAudioEndpointVolumeCallback)
verträgt sich gar nicht.

Ich muss das MasterVolume von TAudioVolume trennen weil beim erstellen einer neuen Instanz von TAudioVolume alle Eigenschaften von MasterVolume nil sind.
Deshalb kann ich auch die Icons nicht freigeben.
Oder aber eine andere Lösung muss her Hmmm...

Glaube das Konzept ist zur zeit noch sehr verworren.

gruss

Geändert von EWeiss ( 9. Mai 2018 um 19:50 Uhr)
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#4

AW: TAudioVolume Komponente incl. System Mixer

  Alt 10. Mai 2018, 04:53
@Tigü

Habe deinen Vorschlag umgesetzt aber sehe im Moment nicht wirklich irgendeinen Vorteil.
Es geht jetzt mal nur um die Events.

Beispiel:
Vorher!

Delphi-Quellcode:
TAudioEndpointEvents = class(TInterfacedObject, IAudioEndpointVolumeCallback)
  private
    MsgHandle: HWND;
    VolMute: TVolMute;
    EventContext: TGUID;
  public
    function OnNotify(pNotify: PAUDIO_VOLUME_NOTIFICATION_DATA): HResult; stdcall;
    procedure SetMsgHandle(WinHandle: HWND);
  end;

function TAudioEndpointEvents.OnNotify(pNotify: PAUDIO_VOLUME_NOTIFICATION_DATA): HResult; stdcall;
var
  VolumeData: AUDIO_VOLUME_NOTIFICATION_DATA;
begin
  VolumeData := pNotify^;
  VolMute.Volume := VolumeData.fMasterVolume;
  VolMute.Muted := VolumeData.bMuted;
  EventContext := VolumeData.guidEventContext;

  PostMessage(MsgHandle, WM_EndpointVolume, integer(@VolMute), integer(@EventContext));

  Result := S_OK;
end;
Nachher!
Delphi-Quellcode:
  TAudioVolume = class(TWinControl, IAudioSessionEvents, IMMNotificationClient,
    IAudioSessionNotification, IAudioEndpointVolumeCallback)
//...
  public
    function OnNotify(pNotify: PAUDIO_VOLUME_NOTIFICATION_DATA): HResult; stdcall;
Delphi-Quellcode:
function TAudioVolume.OnNotify(pNotify: PAUDIO_VOLUME_NOTIFICATION_DATA): HResult;
var
  VolumeData: AUDIO_VOLUME_NOTIFICATION_DATA;
begin
  VolumeData := pNotify^;
  VolMute.Volume := VolumeData.fMasterVolume;
  VolMute.Muted := VolumeData.bMuted;
  EventContext := VolumeData.guidEventContext;

  PostMessage(MsgHandle, WM_EndpointVolume, integer(@VolMute), integer(@EventContext));

  Result := S_OK;

end;
Wo ist jetzt der Vorteil von deiner <> meiner Auslegung?
Das erschließt sich mir nicht. Sorry

PS:
Hab Foobar 2000 mal installiert.
Und nein wie vorher schon gesagt es wird nie ein Event ausgelöst vom System.

Kein OnSessionCreated
Kein OnSessionDisconnected

gruss

Geändert von EWeiss (10. Mai 2018 um 05:32 Uhr)
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.079 Beiträge
 
Delphi 10.4 Sydney
 
#5

AW: TAudioVolume Komponente incl. System Mixer

  Alt 10. Mai 2018, 07:21
Jetzt kannst du das Postmessage weglassen und direkt reagieren.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#6

AW: TAudioVolume Komponente incl. System Mixer

  Alt 10. Mai 2018, 07:27
Jetzt kannst du das Postmessage weglassen und direkt reagieren.
OK nur mein bestreben ist das gerade keine unnötigen externen Funktionen ausgeführt werden müssen.
Die Komponente soll so einfach wie möglich gehalten werden.

zu dem basiert das komplette Control auf diesen Event.
Delphi-Quellcode:
    if not(csDesigning in ComponentState) then
      FEventHandle := AllocateHWnd(ProcessMsg);
Delphi-Quellcode:
procedure TAudioVolume.ProcessMsg(var Msg: TMessage);
var
  PVolMuteRec: PVolMute;
  Volume: single;
  Muted: boolean;
  Device: IMMDevice;
  DeviceId: WideString;
  DeviceInfo: TDeviceInfo;
  HR: HResult;
  NewState: DWORD;
  MyRegistry: TRegistry;
begin
  case Msg.Msg of

    WM_EndpointVolume:
      begin
        PVolMuteRec := PVolMute(Msg.WPARAM);
        if Assigned(tbMasterVolume) then
        begin
          tbMasterVolume.Position := round((1.0 - PVolMuteRec^.Volume) * tbMasterVolume.Max);
          ckMasterMute.Checked := PVolMuteRec^.Muted;
        end;
        if Assigned(tbMasterBalance) then
          AdjustMasterBalancePos;

        if Assigned(FOnMasterVolumeEvent) then
          FOnMasterVolumeEvent(MyVolSet, PVolMuteRec^.Volume, PVolMuteRec^.Muted);
      end;

    WM_VolumeEvent:
      begin
        PVolMuteRec := PVolMute(Msg.WPARAM);

        if MySessionVolSet or Assigned(FOnSessionVolumeEvent) then
        begin
          if Assigned(tbSessionVolume) or Assigned(FOnSessionVolumeEvent) then
          begin
            tbSessionVolume.Position := round((1.0 - PVolMuteRec^.Volume) * tbSessionVolume.Max);
            ckSessionMute.Checked := PVolMuteRec^.Muted;
          end;

          if (MySessionVolSet and (abs(PVolMuteRec^.Volume - MyVolVal) < 0.0001)) then
            MySessionVolSet := false
          else if (MyMuteSet and (PVolMuteRec^.Muted = MyMuteVal)) then
            MyMuteSet := false;

          if Assigned(tbSessionBalance) then
            AdjustSessionBalancePos;
        end;
      end;

    WM_SessionStateEvent:
      begin
        if Assigned(FOnSessionStateEvent) then
          FOnSessionStateEvent(self, Msg.WPARAM);
      end;

    WM_DeviceStateChange, WM_DeviceAdded, WM_DeviceRemoved:
      begin
        DeviceId := WideString(PWideChar(Msg.WPARAM));
        NewState := Msg.LPARAM;
        // Just refresh device list to simplify the logic.
        RefreshDeviceList(DeviceEnumerator);
        // SetupDefaultAudioEndpoint(DeviceEnumerator);
        if Assigned(FOnDeviceStateChange) then
        begin
          if Msg.Msg = WM_DeviceStateChange then
            FOnDeviceStateChange(DeviceId, NewState)
          else if Msg.Msg = WM_DeviceAdded then
            FOnDeviceStateChange(DeviceId, DEVICE_STATE_ADDED)
          else if Msg.Msg = WM_DeviceRemoved then
            FOnDeviceStateChange(DeviceId, DEVICE_STATE_REMOVED);
        end;
      end;

    WM_SessionDisconnected:
      begin
        FAudioSessionList.SessionDisconnected := cAudioSessionDisconnected
          [TAudioSessionDisconnected(Msg.WPARAM)];

        if Assigned(FOnSessionDisconnected) then
          FOnSessionDisconnected(self, Msg.WPARAM);
      end;

    WM_SessionCreate:
      begin
        if Assigned(FOnSessionCreated) then
          FOnSessionCreated(IAudioSessionControl(@Msg.WPARAM));
      end;

    WM_DefaultDeviceChange:
      begin
        HR := DeviceEnumerator.GetDefaultAudioEndpoint(eRender, eMultimedia, Device);
        if HR <> S_OK then
          raise Exception.Create('Error : Unable to get DefaultAudioEndpoint Device');
        DeviceInfo := GetDeviceInfo(Device);
        if DeviceInfo.DeviceId <> FDefaultDevice.DeviceId then
        begin
          FDefaultDevice := DeviceInfo;
          if Assigned(FOnDefaultDeviceChange) then
            FOnDefaultDeviceChange(DeviceInfo);
        end;
      end;

    MM_MIXM_LINE_CHANGE:
      begin
        // wParam = (WPARAM) hMixer lParam = (LPARAM) dwLineID

      end;

    MM_MIXM_CONTROL_CHANGE:
      begin
        // wParam = (WPARAM) hMixer lParam = (LPARAM) dwControlID
        if (DWORD(Msg.LPARAM) <> MasterMute.dwControlID) and
          (DWORD(Msg.LPARAM) <> MasterVol.dwControlID) then
          exit;

        Muted := IsMasterMuted;
        Volume := GetMasterVolume;
        if (DWORD(Msg.LPARAM) = MasterMute.dwControlID) then
        begin
          if (MyMuteSet and (Muted = MyMuteVal)) then
            MyMuteSet := false;
        end
        else
        // for (Msg.LParam = MasterVol.dwControlID)
          if (MyVolSet and (abs(Volume - MyVolVal) < 0.0001)) then
          MyVolSet := false;

        if Assigned(tbMasterVolume) then
        begin
          tbMasterVolume.Position := round((1.0 - Volume) * tbMasterVolume.Max);
          ckMasterMute.Checked := Muted;
        end;

        if Assigned(tbMasterBalance) then
          AdjustMasterBalancePos;
      end;
  else
    if Msg.Msg = WINMM_DEVICECHANGE then
    begin
      MyRegistry := TRegistry.Create;
      MyRegistry.RootKey := HKEY_CURRENT_USER;
      if MyRegistry.KeyExists('Software\Microsoft\Multimedia\Sound Mapper') then
        if MyRegistry.OpenKey('Software\Microsoft\Multimedia\Sound Mapper', true) then
          FDefaultDevice.DeviceName := MyRegistry.ReadString('Playback');
      MyRegistry.free;
    end
    else
      Msg.Result := DefWindowProc(FEventHandle, Msg.Msg, Msg.WPARAM, Msg.LPARAM);
  end;
end;
Kannst du dir vorstellen was ich dann alles ändern müsste?
Das ist nicht mal eben, mache die Events Public in TAudioVolume da hängt noch viel mehr von ab.

gruss

Geändert von EWeiss (10. Mai 2018 um 07:35 Uhr)
  Mit Zitat antworten Zitat
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.079 Beiträge
 
Delphi 10.4 Sydney
 
#7

AW: TAudioVolume Komponente incl. System Mixer

  Alt 10. Mai 2018, 19:24
Der Aufwand wäre nur, die ganze processmsg-Methode wegzumachen und die einzelnen Teile rauszukopieren und anstatt den jeweiligen PostMessage-Aufrufen hinzukopieren. Dazu noch prüfen if Mainthread <> GetCurrentThreadId then Sync.
Alles in allen keine 10 min Arbeit und auch nur wenn man sich sehr viel Zeit lässt beim Drücken von Strg+C und Strg+V.
Am Ende haste viel weniger Quelltext gesamt gesehen. Außerdem gehen dann die Sachen, wo du Referenzgezählte Sachen weiterreichst.
  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 10:14 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