DSPack - How to get the default device for sound output?

Deadly 提交于 2019-12-03 17:19:06

Here's a method that queries the driver for preferred playback device(http://msdn.microsoft.com/en-us/library/aa909815.aspx), GetWaveOutDeviceList will return the list of devices, GetWaveOutDevice will return the index in the list of the prefered device.

// this method will return the index in the list
function GetWaveOutDevice: Cardinal;
const
  DRVM_MAPPER=$2000;
  DRVM_MAPPER_PREFERRED_GET = DRVM_MAPPER + 21;
  DRVM_MAPPER_PREFERRED_SET = DRVM_MAPPER + 22;
var
 LDW2: Cardinal;
begin
 Result := $FFFFFFFF;
 LDW2 := 0;
 waveOutMessage( WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, DWORD( @Result ), DWORD( @LDW2 ) );
end;

// this method will retrieve the list of devices
procedure GetWaveOutDeviceList(List: TStrings);
var
 Index: Integer;
 LCaps: WAVEOUTCAPS;
begin
  List.Clear;
  for Index := 0 to waveOutGetNumDevs -1 do begin
    waveOutGetDevCaps( Index, @LCaps, SizeOf( LCaps ) );
    List.add( LCaps.szPname );
  end;
end;

If you would like to get the recording devices, just replace "WaveOut" with "WaveIn" in the above to methods.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!