Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#44

AW: TAudioVolume Komponente incl. System Mixer

  Alt 8. Mai 2018, 22:23
Neue Version nur Master Icon addiert.
Mache jetzt erst mal pause mit dem Kram wegen den Event Problemen.
Hier ein Beispiel!
Delphi-Quellcode:
unit AudioSessionNotification;

interface

uses
  Windows, Messages, Classes, AudioSessionControl, Constants;

type
   IAudioSessionNotification = interface(IUnknown)
  ['{641DD20B-4D41-49CC-ABA3-174B9477BB08}']
    function OnSessionCreated(const NewSession: IAudioSessionControl): HResult; stdcall;
  end;

  TAudioSessionNotification = class(TInterfacedObject, IAudioSessionNotification)
  private
    MsgHandle: HWND;
  public
    function OnSessionCreated(const NewSession: IAudioSessionControl): HResult; stdcall;
    procedure SetMsgHandle(WinHandle: HWND);
  end;

implementation

{ TSessionNotification }

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

  Result := S_OK;
end;

procedure TAudioSessionNotification.SetMsgHandle(WinHandle: HWND);
begin

  MsgHandle := WinHandle;
end;

end.
Ich erstelle das Event.
Delphi-Quellcode:
TAudioVolume.Create..
var
  ISessionNotification: TAudioSessionNotification;
//...
// SessionNotification
ISessionNotification := TAudioSessionNotification.Create;
ISessionNotification.SetMsgHandle(FEventHandle);
SessionNotification := ISessionNotification;
Dann registriere ich das Notification
Delphi-Quellcode:
// Register TAudioSessionNotification to receive a notification when a session is created.
HR := SessionManager2.RegisterSessionNotification(SessionNotification);
if HR <> S_OK then
  raise Exception.Create('Error : Unable to Register Session Notification');
Jetzt sollte hier wenn eine neue Session erstellt wird außerhalb der Anwendung
Delphi-Quellcode:
function TAudioSessionNotification.OnSessionCreated(const NewSession: IAudioSessionControl): HResult;
begin
  PostMessage(MsgHandle, WM_SessionCreate, integer(@NewSession), 0);

  Result := S_OK;
end;
Das Event feuern tut es aber nicht auch das nicht OnSessionDisconnected.
Das war nur zur Info.

Ihr habt den Source also tobt euch aus.

gruss

Geändert von EWeiss ( 8. Mai 2018 um 23:00 Uhr)
  Mit Zitat antworten Zitat