怎样通过API打开和关闭麦克的静音? (50分)

  • 主题发起人 主题发起人 1dyi
  • 开始时间 开始时间
1

1dyi

Unregistered / Unconfirmed
GUEST, unregistred user!
那位大侠可以回答:怎样通过API打开和关闭麦克的静音? 还有怎么控制麦克音量,希望正面回答问题.不要粘贴一大堆没用的东东..好让浏览此问题的朋友受益..谢谢各位了..
 
我只能提示:
用这个函数mixersetcontroldetails;
找一个好的Multimedia控件一切都OK,
如果明天上午还没有人提供答案,
我去找找,来Show一下,
顺便顶一下,呵呵~~~~~~~~~~~~~~~~~~~~~~~~~~
 
呵,来收分了.
 
uses
MMSystem;


// Setzt die Lautstärke für das Mikrofon
// Set the volume for the microphone

function SetMicrophoneVolume(bValue: Word): Boolean;

var {0..65535}
hMix: HMIXER;

mxlc: MIXERLINECONTROLS;

mxcd: TMIXERCONTROLDETAILS;

vol: TMIXERCONTROLDETAILS_UNSIGNED;

mxc: MIXERCONTROL;

mxl: TMixerLine;

intRet: Integer;

nMixerDevs: Integer;

begin

// Check if Mixer is available
// Überprüfen, ob ein Mixer vorhanden
nMixerDevs := mixerGetNumDevs();

if (nMixerDevs < 1) then

begin

Exit;

end;



// open the mixer
intRet := mixerOpen(@hMix, 0, 0, 0, 0);

if intRet = MMSYSERR_NOERROR then

begin

mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;

mxl.cbStruct := SizeOf(mxl);


// get line info
intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);


if intRet = MMSYSERR_NOERROR then

begin

ZeroMemory(@mxlc, SizeOf(mxlc));

mxlc.cbStruct := SizeOf(mxlc);

mxlc.dwLineID := mxl.dwLineID;

mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;

mxlc.cControls := 1;

mxlc.cbmxctrl := SizeOf(mxc);


mxlc.pamxctrl := @mxc;

intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);


if intRet = MMSYSERR_NOERROR then

begin

{
// Microphone Name
Label1.Caption := mxlc.pamxctrl.szName;


// Min/Max Volume
Label2.Caption := IntToStr(mxc.Bounds.dwMinimum) + '->' + IntToStr(mxc.Bounds.dwMaximum);

}
ZeroMemory(@mxcd, SizeOf(mxcd));

mxcd.dwControlID := mxc.dwControlID;

mxcd.cbStruct := SizeOf(mxcd);

mxcd.cMultipleItems := 0;

mxcd.cbDetails := SizeOf(Vol);

mxcd.paDetails := @vol;

mxcd.cChannels := 1;


// vol.dwValue := mxlc.pamxctrl.Bounds.lMinimum;
Set min. Volume / Minimum setzen
// vol.dwValue := mxlc.pamxctrl.Bounds.lMaximum;
Set max. Volume / Maximum setzen
vol.dwValue := bValue;


intRet := mixerSetControlDetails(hMix, @mxcd,
MIXER_SETCONTROLDETAILSF_VALUE);

if intRet <> MMSYSERR_NOERROR then

ShowMessage('SetControlDetails Error');

end
else

ShowMessage('GetLineInfo Error');

end;


intRet := mixerClose(hMix);

end;


end;



procedure TForm1.Button1Click(Sender: TObject);

begin

SetMicrophoneVolume(30000);

end;



{********************************************************}


// Enable/disable "Mute Microphone Volume"
// Ton für Mikrofon ein/ausschalten

function SetMicrophoneVolumeMute(bMute: Boolean): Boolean;

var
hMix: HMIXER;

mxlc: MIXERLINECONTROLS;

mxcd: TMIXERCONTROLDETAILS;

vol: TMIXERCONTROLDETAILS_UNSIGNED;

mxc: MIXERCONTROL;

mxl: TMixerLine;

intRet: Integer;

nMixerDevs: Integer;

mcdMute: MIXERCONTROLDETAILS_BOOLEAN;

begin

// Check if Mixer is available
// &amp;Uuml;berprüfen, ob ein Mixer vorhanden ist
nMixerDevs := mixerGetNumDevs();

if (nMixerDevs < 1) then

begin

Exit;

end;



// open the mixer
// Mixer &amp;ouml;ffnen
intRet := mixerOpen(@hMix, 0, 0, 0, 0);

if intRet = MMSYSERR_NOERROR then

begin

mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;

mxl.cbStruct := SizeOf(mxl);


// mixerline info
intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);


if intRet = MMSYSERR_NOERROR then

begin

ZeroMemory(@mxlc, SizeOf(mxlc));

mxlc.cbStruct := SizeOf(mxlc);

mxlc.dwLineID := mxl.dwLineID;

mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;

mxlc.cControls := 1;

mxlc.cbmxctrl := SizeOf(mxc);

mxlc.pamxctrl := @mxc;


// Get the mute control
// Mute control ermitteln
intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);


if intRet = MMSYSERR_NOERROR then

begin

ZeroMemory(@mxcd, SizeOf(mxcd));

mxcd.cbStruct := SizeOf(TMIXERCONTROLDETAILS);

mxcd.dwControlID := mxc.dwControlID;

mxcd.cChannels := 1;

mxcd.cbDetails := SizeOf(MIXERCONTROLDETAILS_BOOLEAN);

mxcd.paDetails := @mcdMute;


mcdMute.fValue := Ord(bMute);


// set, unset mute
// Stumsschalten ein/aus
intRet := mixerSetControlDetails(hMix, @mxcd,
MIXER_SETCONTROLDETAILSF_VALUE);

{
mixerGetControlDetails(hMix, @mxcd,
MIXER_GETCONTROLDETAILSF_VALUE);

Result := Boolean(mcdMute.fValue);

}
Result := intRet = MMSYSERR_NOERROR;


if intRet <> MMSYSERR_NOERROR then

ShowMessage('SetControlDetails Error');

end
else

ShowMessage('GetLineInfo Error');

end;



intRet := mixerClose(hMix);

end;


end;



procedure TForm1.Button1Click(Sender: TObject);

begin

SetMicrophoneVolumeMute(False);

end;
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部