在 Delphi 下使用 DirectSound (1): 枚举播放设备
2011-01-12 20:26
441 查看
现在的 Delphi(2010、XE) 已经自带了 DirectX 的相关单元(...\source\rtl\win\).
这是常见的代码:
在回调函数中直接使用窗体控件不好, 修改如下:
获取更多信息:
//枚举函数 function DirectSoundEnumerate( lpDSEnumCallback: TDSEnumCallback; //回调函数 lpContext: Pointer //用户指针 ): HResult; stdcall; //返回错误代码, 成功则返回 DS_OK(0) //DirectSoundEnumerate 需要的回调函数的原形: TDSEnumCallback = function( lpGuid: PGUID; //设备的 GUID lpcstrDescription: PChar; //设备描述 lpcstrModule: PChar; //模块标识 lpContext: Pointer //由 DirectSoundEnumerate 提供的用户指针 ): BOOL; stdcall; //返回 True 表示要继续枚举, 不在继续找了就返回 False
这是常见的代码:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; //只在窗体上放了一个列表框 procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses DirectSound; //! function EnumCallback(lpGuid: PGUID; lpcstrDescription, lpcstrModule: PChar; lpContext: Pointer): BOOL; stdcall; begin Form1.ListBox1.Items.Add(lpcstrDescription); Result := True; end; procedure TForm1.FormCreate(Sender: TObject); begin DirectSoundEnumerate(EnumCallback, nil); end; end.
在回调函数中直接使用窗体控件不好, 修改如下:
uses DirectSound; function EnumCallback(lpGuid: PGUID; lpcstrDescription, lpcstrModule: PChar; lpContext: Pointer): BOOL; stdcall; begin TStrings(lpContext).Add(lpcstrDescription); Result := True; end; procedure TForm1.FormCreate(Sender: TObject); begin DirectSoundEnumerate(EnumCallback, ListBox1.Items); end;
获取更多信息:
uses DirectSound; function EnumCallback(lpGuid: PGUID; lpcstrDescription, lpcstrModule: PChar; lpContext: Pointer): BOOL; stdcall; begin if lpGuid <> nil then TStrings(lpContext).Add(GUIDToString(lpGuid^)); TStrings(lpContext).Add(lpcstrDescription); if lpcstrModule <> nil then TStrings(lpContext).Add(lpcstrModule); TStrings(lpContext).Add(EmptyStr); Result := True; end; procedure TForm1.FormCreate(Sender: TObject); begin DirectSoundEnumerate(EnumCallback, ListBox1.Items); end;
相关文章推荐
- 在 Delphi 下使用 DirectSound (3): 播放第一个 Wave 文件
- 在 Delphi 下使用 DirectSound (7): 播放资源文件中的 Wave 数据
- 在 Delphi 下使用 DirectSound (2): 查看设备性能
- 在 Delphi 下使用 DirectSound (6): 按文件自己的格式(TWaveFormatEx)播放
- 在 Delphi 下使用 DirectSound (7): 播放资源文件中的 Wave 数据
- 在 Delphi 下使用 DirectSound (4): 设置音量、相位、播放频率和播放位置
- 在 Delphi 下使用 DirectSound (11): 测试压缩效果器 IDirectSoundFXCompressor8
- 在 Delphi 下使用 DirectSound (18): 3D 特效
- 使用DirectSound播放PCM音频数据
- mpg123解码MP3,使用DirectSound播放乐曲
- 在 Delphi 下使用 DirectSound (9): 效果器初步及 IDirectSoundFXGargle8 效果器
- 在 Delphi 下使用 DirectSound (14): 测试镶边效果器 IDirectSoundFXFlanger8
- 使用多媒体API枚举音频设备 - zgl7903的专栏 - CSDNBlog
- 在 Delphi 下使用 DirectSound (11): 测试压缩效果器 IDirectSoundFXCompressor8
- c#使用WPD读取便携式设备信息一(枚举设备、连接设备及读取设备信息)
- HOWTO: 通过使用 SetupDi 调用函数枚举硬件设备
- 在 Delphi 下使用 DirectSound (15): 测试混响效果器 IDirectSoundFXWavesReverb8
- DirectSound---输出设备基本操作(枚举、查询等)
- 使用libusb库枚举mac设备下面的USB设备
- 使用Delphi开发多媒体播放音轨问题的FAQ(原创)