熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

DELPHI操縱聲卡

2022-06-13   來源: Delphi編程 

  檢查聲卡是否安裝

  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;


From:http://tw.wingwit.com/Article/program/Delphi/201311/24686.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.