Question

I wonder how I can to set my default audio capture device (microphone) through Delphi.

I'm trying to use the functions of mmsystem api, following my code

procedure TForm1.Button1Click(Sender: TObject);
var
 DevOutCaps: TWaveOutCaps;
 DevInCaps: TWaveInCaps;
 n, i: Integer;
 s: String;
begin
n := waveInGetNumDevs;
for i := 0 to n-1 do
  begin
    waveInGetDevCaps(i, @DevInCaps, SizeOf(DevInCaps));
    s := PChar(@DevInCaps.szPname);
    ListBox1.Items.Add(s);
  end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
 Ndev : Integer;
 Adev : Integer;
begin
Ndev := AudioInDeviceNameToDeviceID(ListBox1.Items.Strings[ListBox1.ItemIndex]);
Adev := GetWaveInDevice;
ShowMessage( IntToStr(Adev) );
ShowMessage(ListBox1.Items.Strings[ListBox1.ItemIndex]);
ShowMessage( IntToStr(Ndev) );
if waveInMessage(HWAVEIN(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_SET, Adev, Ndev) = MMSYSERR_NOTSUPPORTED then
   begin
   MessageDlg('NOT SUPPORTED', mtInformation, [mbOK], 0);
   end;

Preferably no third party components. Thank you

Was it helpful?

Solution

The WinMM API would seem to be the way to go, using the DRVM_MAPPER_PREFERRED_SET message Apparently, it is supported although undocumented under Win32 :-

WinMM API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top