DSPack - 如何获取声音输出的默认设备?
在 Windows 7 中,有多个播放设备。
示例(在我的笔记本电脑上): 扬声器和双耳机 独立双耳机 SPDIF(通过 HP Dock 进行数字输出)
情况如下: 我正在编写一个应用程序,让用户选择输出设备并将其保存到应用程序的设置中。因此,它为用户提供了组合框中所有 Directsound 设备的选择。用户选择他喜欢的一项并保存。
我的要求是: 初始加载此列表时,我想选择默认设备(如 Windows 7 - 控制面板 -> 声音 -> 播放选项卡中设置),
因此我枚举音频输出设备的代码是:
代码:
procedure TForm1.FillDevices;
var
AudioDevEnum: TSysDevEnum;
n: string;
i, ps: integer;
begin
AudioDevEnum := TSysDevEnum.Create(CLSID_AudioRendererCategory);
try
if AudioDevEnum.CountFilters = 0 then
Exit;
for i := 0 to AudioDevEnum.CountFilters - 1 do
begin
n := AudioDevEnum.Filters[i].FriendlyName;
ps := pos('DirectSound: ', n);
if ps <> 0 then
begin
ps := pos('Modem', n);
if ps = 0 then
begin
// Delete(n, 1, 13);
lstDevices.Items.Add(n);
end;
end;
end;
lstDevices.ItemIndex := 0;
finally
AudioDevEnum.Free;
end;
end;
获取列表后,我想检测声音控制面板中设置为“默认设备”的项目,然后选择它。这样应用程序就能第一次保存正确的设备,而无需用户执行此工作。
这可以做到吗?如何?
提前致谢。
编辑:请注意,我想选择并保存(到 INI 文件)默认设备,以便我的应用程序可以使用它来输出声音(通过 DSPack 组件)。我不想更改 Windows 设置。
In Windows 7 there are multiple playback devices.
Example (on my laptop):
Speakers and Dual Headphones
Independent Dual Headphones
SPDIF (Digital Out via HP Dock)
The situation is thus:
I am writing an app that lets the user choose the output device and save this into the settings of the app. So it offers the user a choice of all Directsound devices in a combobox. The user selects the one he prefers and saves it.
My requirement is:
On initial load of this list, I want to select the default device (as set in Windows 7 - Control Panel -> Sound -> Playback tab)
So my code to enumerate the audio output devices is:
Code:
procedure TForm1.FillDevices;
var
AudioDevEnum: TSysDevEnum;
n: string;
i, ps: integer;
begin
AudioDevEnum := TSysDevEnum.Create(CLSID_AudioRendererCategory);
try
if AudioDevEnum.CountFilters = 0 then
Exit;
for i := 0 to AudioDevEnum.CountFilters - 1 do
begin
n := AudioDevEnum.Filters[i].FriendlyName;
ps := pos('DirectSound: ', n);
if ps <> 0 then
begin
ps := pos('Modem', n);
if ps = 0 then
begin
// Delete(n, 1, 13);
lstDevices.Items.Add(n);
end;
end;
end;
lstDevices.ItemIndex := 0;
finally
AudioDevEnum.Free;
end;
end;
After getting the list, I want to detect the item which is set as the 'default device' in the sound control panel, and select it. This is so that application saves the correct device the first time without needing the user to do this job.
Can this be done? How?
Thanks in advance.
EDIT: Note that I want to select and save (to INI file) the default device so that it can be used by my application to output sound (via the DSPack component). I do not want to change the Windows setting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是查询首选播放设备的驱动程序的方法(http://msdn.microsoft .com/en-us/library/aa909815.aspx),GetWaveOutDeviceList将返回设备列表,GetWaveOutDevice将返回首选设备列表中的索引 设备。
如果您想获取录音设备,只需将上面方法中的“WaveOut”替换为“WaveIn”即可。
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.
If you would like to get the recording devices, just replace "WaveOut" with "WaveIn" in the above to methods.