Mirror

Muting and revoicing the audio from your application (Views: 707)


Problem/Question/Abstract:

Based on an old article that described the solution for muting the audio during my application, someone asked me to make a similar to be controlled from a Button: here's the solution... easy and fast!

Answer:

WARNING: you must avoid pressing 2 times the mute button or the mixer data will be lost. so I added a boolean condition.

uses
  MMSystem;

{...}

{Global variables}

var
  MyVolume: array[0..10] of LongInt;
  mDevs: Integer;
  IsMute: Boolean;

Create two button:

cmdMute
cmdRevoice

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  IsMute := False;
end;

procedure TfrmMain.cmdMuteClick(Sender: TObject);
var
  I: Integer;
begin
  if (not (IsMute)) then
  begin
    mDevs := auxGetNumDevs;
    for I := 0 to mDevs do
    begin
      auxGetVolume(I, Addr(MyVolume[I]));
      auxSetVolume(I, LongInt(9000) * 65536 + LongInt(9000));
    end;
    IsMute := True;
  end;
end;

procedure TfrmMain.cmdRevoiceClick(Sender: TObject);
var
  I: Integer;
begin
  if (IsMute) then
  begin
    for I := 0 to mDevs do
      auxSetVolute(I, MyVolume[I]);
    IsMute := False;
  end;
end;

<< Back to main page