检查声卡是否安装
uses mmsystem;
function Soundkarte:Boolean;
begin
Result := WaveOutGetNumDevs >;
end;
检测声卡存在
如果你是做一些多媒体播放器之类的程序时为了完善系统的容错性就必须用到一些检测系统的功能其中检测声卡是否存在就是一个问题下列程序帮你忙首先需要在uses部分加入mmsystem 接着在窗体创建时检测声卡
procedure TFormFormCreate(Sender TObject)
var iInteger
begin
i = auxGetNumDevs()
if i<= then
labelCaption =系统没有发现声卡
end
控制声音音量
当你做一个多媒体播放器时难免少不了控制音量的大小和左右声道的播放下面就介绍一种控制Wave波形输出设备音量的方法该方法不是设置主音量先在窗体上放两个TTrackBar分别命名为TrackBarTrackBar属性Max都设置为如果觉得刻度太密了可以把Frequency属性值设置大一些然后在Uses段加入MMSystem并在TrackBar和TrackBar的OnChange事件都写上下列语句
procedure TFormTrackBarChange(Sender: TObject);
var Wave:string;
begin
Wave:=$+inttohex(TrackBarPosition
)+inttohex(TrackBarPosition
);
waveoutsetvolume(
strtoint(Wave));
end;
获得和控制音量
unit uMain;
interface
uses
Windows
Messages
SysUtils
Classes
Controls
Forms
Dialogs
ExtCtrls
StdCtrls
mmsystem; //You must add this in the uses line
type
TForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
myvolume: array[] of longint;
{ Public declarations }
end;
var
Form: TForm;
implementation
{$R *DFM}
procedure TFormFormCreate(Sender: TObject);
var
Count
i: integer;
begin
Count := auxGetNumDevs;
for i := to Count do
begin//The i is the device: IE =Wav Volume
auxgetvolume(i
addr(myvolume[i])); //Gets the values that the user has set
auxsetvolume(i
longint()*+longint()); //Sets the volume very very low
end; //The reason for the * + is if you wanted to do left and right channels
end;
procedure TFormFormClose(Sender: TObject; var Action: TCloseAction);
var
Count
i: integer;
begin
Count := auxGetNumDevs;
for i := to Count do
begin
auxsetvolume(i
myvolume[i]); //Sets the volume back to the users old settings
end;
end;