Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Desactivar microfono de la PC (https://www.clubdelphi.com/foros/showthread.php?t=65853)

fide_uci 18-01-2010 15:21:03

Desactivar microfono de la PC
 
Hola amigos. Me sucede lo siguiente. Necesito hacer un programa que cuando yo quiera mediante un boton desactive el microfono de la PC, es desir lo apague para que no tenga entrada. O si tiene entrada que la PC lo ignore. Alguien sabe como hacer esto??

Gracias de antemano para todos !!!

delphi.com.ar 18-01-2010 15:34:02

Debes hacerlo mediante el mixer de windows, te paso una unit que alguna vez escribí y como utilizarla:

Código Delphi [-]
{********************************************************}
{                                                        }
{    Multimedia Utils                                    }
{                                                        }
{    Autor: Federico Firenze                             }
{    enero de 2003                                       }
{                                                        }
{********************************************************}

unit MMUtils;

interface

uses
  Windows;

procedure mmMixSetVolume(AComponentType, AValue: DWORD);
procedure mmMixSetMute(AComponentType: DWORD; AValue: boolean);

implementation

uses
  SysUtils, MMSystem;

procedure RaiseLastMMError;
begin
  { TODO : .. }
  RaiseLastOsError;
end;

procedure mmMixSetDetail(AComponentType, AControlType: DWORD; Data: Pointer; DataSize: DWORD);
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
begin
  if (mixerGetNumDevs() > 0) then
  begin
    if mixerOpen(@hMix, 0, 0, 0, 0) = MMSYSERR_NOERROR then
      try
        mxl.dwComponentType := AComponentType;
        mxl.cbStruct := SizeOf(mxl);

        if mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR then
        begin
          ZeroMemory(@mxlc, SizeOf(mxlc));

          mxlc.cbStruct := SizeOf(mxlc);
          mxlc.dwLineID := mxl.dwLineID;
          mxlc.dwControlType := AControlType;
          mxlc.cControls := 1;
          mxlc.cbmxctrl := SizeOf(mxc);
          mxlc.pamxctrl := @mxc;

          if mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR then
          begin
            ZeroMemory(@mxcd, SizeOf(mxcd));
            mxcd.dwControlID := mxc.dwControlID;
            mxcd.cbStruct := SizeOf(mxcd);
            mxcd.cMultipleItems := 0;
            mxcd.cbDetails := DataSize;
            mxcd.paDetails := Data;
            mxcd.cChannels := 1;

            if mixerSetControlDetails(hMix, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE) <> MMSYSERR_NOERROR then
              RaiseLastMMError;
          end else
            RaiseLastMMError;
        end else
          RaiseLastMMError;
      finally
        if mixerClose(hMix) <> MMSYSERR_NOERROR then
         RaiseLastMMError;
      end;
  end;
end;

procedure mmMixSetVolume(AComponentType, AValue: DWORD);
var
  uValue: TMIXERCONTROLDETAILS_UNSIGNED;
begin
  uValue.dwValue := AValue;
  mmMixSetDetail(AComponentType, MIXERCONTROL_CONTROLTYPE_VOLUME, @uValue, SizeOf(uValue));
end;


procedure mmMixSetMute(AComponentType: DWORD; AValue: boolean);
var
  bValue: MIXERCONTROLDETAILS_BOOLEAN;
begin
  bValue.fValue := Ord(AValue);
  mmMixSetDetail(AComponentType, MIXERCONTROL_CONTROLTYPE_MUTE, @bValue, SizeOf(bValue));
end;

end.

Aquí utiliza la función mmMixSetMute para poner el micrófono en estado mute, para salir de este estado el segundo parámetro debería ser False.
Código Delphi [-]
uses MMUtils, MMSystem;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  mmMixSetMute(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, True);
end;

Saludos!

Neftali [Germán.Estévez] 18-01-2010 16:01:09

Se puede hacer utilizando la API waveOutSetVolume (msdn).

Pásate por aquí y prueba este ejemplo (que la utiliza) a ver si te funciona.

fide_uci 18-01-2010 19:01:02

Ufff. Verda que ustedes si que son los mejores ejejeje !
Tks y espero poder ayudarlos algun dia xD.

fide_uci 18-01-2010 19:22:33

Ese del microfono me dice.
Error call to undefined os function.

Que puede ser eso ??

fide_uci 18-01-2010 19:28:44

Es decir: Le mensaje de error dice.

A Call to an OS function failed cuando pongo esto.

Código Delphi [-]
mmMixSetMute(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, True);

fide_uci 18-01-2010 19:43:24

Bueno Neftali, el link que me das esos codigos me trabajan de (http://www.swissdelphicenter.ch/en/showcode.php?id=225) maravillas lo unico que no se como poner el microfono en esta linea.

Código Delphi [-]
if GetVolumeControl(MyMixerHandle, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
        MIXERCONTROL_CONTROLTYPE_VOLUME, MyVolCtrl) then

He probado con

MIXERLINE_COMPONENTTYPE_DST_WAVEIN
y con
MIXERLINE_COMPONENTTYPE_DST_VOICEIN

Pero ninguno de los 2 me baja el volumen, pero bueno tengo que tener un microfono, cuando confirme les digo.

Gracias de todas formas !!!

delphi.com.ar 18-01-2010 20:38:44

Cita:

Empezado por fide_uci (Mensaje 351063)
Es decir: Le mensaje de error dice.

A Call to an OS function failed cuando pongo esto.

Código Delphi [-]
mmMixSetMute(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE, True);

Fíjate en que línea de la función mmMixSetDetail es que falla, para tener mas información.

Saludos!

fide_uci 18-01-2010 21:46:54

Donde da el error.
 
El error lo muestra en esta linea.

(Linea 49 de la Unit MMUtils)

if mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR then

y de ahi salta para esta linea (de MMUtils)

RaiseLastMMError; (Linea 70)


La franja horaria es GMT +2. Ahora son las 17:38:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi