Einzelnen Beitrag anzeigen

FarAndBeyond
(Gast)

n/a Beiträge
 
#17

AW: Lausprechersteuerung

  Alt 22. Sep 2015, 21:06
Das hier läuft unter D7 sehr gut...

Delphi-Quellcode:
 Type
  IAudioEndpointVolumeCallback = Interface(IUnknown)
  ['{657804FA-D6AD-4496-8A60-352752AF4F89}']
  End;

  IAudioEndpointVolume = Interface(IUnknown)
   ['{5CDF2C82-841E-4546-9722-0CF74078229A}']
    Function RegisterControlChangeNotify(AudioEndPtVol: IAudioEndpointVolumeCallback): HRESULT; Stdcall;
    Function UnregisterControlChangeNotify(AudioEndPtVol: IAudioEndpointVolumeCallback): HRESULT; Stdcall;
    Function GetChannelCount(Out PInteger): HRESULT; Stdcall;

    Function SetMasterVolumeLevel(fLevelDB: Single; pguidEventContext: PGUID): HRESULT; Stdcall;
    Function SetMasterVolumeLevelScalar(fLevelDB: Single; pguidEventContext: PGUID): HRESULT; Stdcall;

    Function GetMasterVolumeLevel(Out fLevelDB: Single): HRESULT; Stdcall;
    Function GetMasterVolumeLevelScalar(Out fLevelDB: Single): HRESULT; Stdcall;

    Function SetChannelVolumeLevel(nChannel: Integer; fLevelDB: Double; pguidEventContext: PGUID): HRESULT; Stdcall;
    Function SetChannelVolumeLevelScalar(nChannel: Integer; fLevelDB: Double; pguidEventContext: PGUID): HRESULT; Stdcall;

    Function GetChannelVolumeLevel(nChannel: Integer; Out fLevelDB: Double): HRESULT; Stdcall;
    Function GetChannelVolumeLevelScalar(nChannel: Integer; Out fLevelDB: Double): HRESULT; Stdcall;

    Function SetMute(bMute: Bool; pguidEventContext: PGUID): HRESULT; Stdcall;
    Function GetMute(Out bMute: Bool): HRESULT; Stdcall;

    Function GetVolumeStepInfo(pnStep: Integer; Out pnStepCount: Integer): HRESULT; Stdcall;
    Function VolumeStepUp(pguidEventContext: PGUID): HRESULT; Stdcall;
    Function VolumeStepDown(pguidEventContext: PGUID): HRESULT; Stdcall;
    Function GetVolumeRange(Out pflVolumeMindB: Double; Out pflVolumeMaxdB: Double; Out pflVolumeIncrementdB: Double): HRESULT; Stdcall;
    Function QueryHardwareSupport(Out pdwHardwareSupportMask): HRESULT; Stdcall;
  End;

  IAudioMeterInformation = Interface(IUnknown)
  ['{C02216F6-8C67-4B5B-9D00-D008E73E0064}']
  End;

  IPropertyStore = Interface(IUnknown)
  End;

  IMMDevice = Interface(IUnknown)
  ['{D666063F-1587-4E43-81F1-B948E807363F}']
   Function Activate(Const refId: TGUID; dwClsCtx: DWORD; pActivationParams: PInteger; Out pEndpointVolume: IAudioEndpointVolume): HRESULT; StdCall;
   Function OpenPropertyStore(stgmAccess: DWORD; Out ppProperties: IPropertyStore): HRESULT; Stdcall;
   Function GetId(Out ppstrId: PLPWSTR): HRESULT; Stdcall;
   Function GetState(Out State: Integer): HRESULT; Stdcall;
  End;

  IMMDeviceCollection = interface(IUnknown)
  ['{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}']
  End;

  IMMNotificationClient = interface(IUnknown)
  ['{7991EEC9-7E89-4D85-8390-6C703CEC60C0}']
  End;

  IMMDeviceEnumerator = interface(IUnknown)
  ['{A95664D2-9614-4F35-A746-DE8DB63617E6}']
   Function EnumAudioEndpoints(dataFlow: TOleEnum; deviceState: SYSUINT; DevCollection: IMMDeviceCollection): HRESULT; Stdcall;
   Function GetDefaultAudioEndpoint(EDF: SYSUINT; ER: SYSUINT; Out Dev: IMMDevice): HRESULT; Stdcall;
   Function GetDevice(pwstrId: pointer; Out Dev: IMMDevice): HRESULT; Stdcall;
   Function RegisterEndpointNotificationCallback(pClient: IMMNotificationClient): HRESULT; Stdcall;
  End;
 
 Const
  CLASS_IMMDeviceEnumerator : TGUID = '{BCDE0395-E52F-467C-8E3D-C4579291692E}';
  IID_IMMDeviceEnumerator : TGUID = '{A95664D2-9614-4F35-A746-DE8DB63617E6}';
  IID_IAudioEndpointVolume : TGUID = '{5CDF2C82-841E-4546-9722-0CF74078229A}';


.....
Var
 single_VolumeLevel : Single = 1.0;
 bool_GetMute : Bool = False;

Procedure SetMasterVolume(single_VolumeLevel : Single);
  Var
   EndpointVolume : IAudioEndpointVolume;
   DeviceEnumerator : IMMDeviceEnumerator;
   Device : IMMDevice;
 Begin
  Try
   CoCreateInstance(CLASS_IMMDeviceEnumerator, Nil, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, DeviceEnumerator);
   DeviceEnumerator.GetDefaultAudioEndpoint($00000000, $00000000, Device);
   Device.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, Nil, EndpointVolume);
   EndpointVolume.SetMasterVolumeLevelScalar(single_VolumeLevel, Nil);
  Except
   Exit;
  End;
 End;


Procedure GetMasterVolume(out single_VolumeLevel : Single);
  Var
   EndpointVolume : IAudioEndpointVolume;
   DeviceEnumerator : IMMDeviceEnumerator;
   Device : IMMDevice;
 Begin
  Try
   CoCreateInstance(CLASS_IMMDeviceEnumerator, Nil, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, DeviceEnumerator);
   DeviceEnumerator.GetDefaultAudioEndpoint($00000000, $00000000, Device);
   Device.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, Nil, EndpointVolume);
   EndpointVolume.GetMasterVolumeLevelScalar(single_VolumeLevel);
  Except
   Exit;
  End;
 End;


Procedure GetMute(Out bool_GetMute: Bool);
  Var
   EndpointVolume : IAudioEndpointVolume;
   DeviceEnumerator : IMMDeviceEnumerator;
   Device : IMMDevice;
 Begin
  Try
   CoCreateInstance(CLASS_IMMDeviceEnumerator, Nil, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, DeviceEnumerator);
   DeviceEnumerator.GetDefaultAudioEndpoint($00000000, $00000000, Device);
   Device.Activate(IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, Nil, EndpointVolume);
   EndpointVolume.GetMute(bool_GetMute);
  Except
   Exit;
  End;
 End;
EDIT: Uses ActiveX, ComOBJ;

Geändert von FarAndBeyond (22. Sep 2015 um 21:16 Uhr)
  Mit Zitat antworten Zitat