Mute PC sound programaticcally?

Just starting out? Need help? Post your questions and find answers here.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Mute PC sound programaticcally?

Post by utopiomania »

Is it possible to mute the PC sound (master volume) programatically? I would like to use a webgadget to
display both images and live video thumbnails, but several movies rolling at the same time tend to sound
rather confusing. :?
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

Code: Select all

; Code : KarLKoX

#MMSYSERR_NOERROR       = 0
#MIXER_SHORT_NAME_CHARS = 16
#MIXER_LONG_NAME_CHARS  = 64
Structure MIXERCONTROL
  cbStruct.l
  dwControlID.l
  dwControlType.l
  fdwControl.l
  cMultipleItems.l
  szShortName.s[#MIXER_SHORT_NAME_CHARS]
  szName.s[#MIXER_LONG_NAME_CHARS]
  lMinimum.l
  lMaximum.l
  reserved.l[10]
EndStructure

Procedure.l MIXER_getVolume(Type.l)
Protected dwVolume.l, result.l, hMixer
Protected ml.MIXERLINE, mlc.MIXERLINECONTROLS,mc.MIXERCONTROL,mcd.MIXERCONTROLDETAILS,mcdu.MIXERCONTROLDETAILS_UNSIGNED

  RtlZeroMemory_(ml,SizeOf(MIXERLINE))
  RtlZeroMemory_(mlc,SizeOf(MIXERLINECONTROLS))
  RtlZeroMemory_(mcd,SizeOf(MIXERCONTROLDETAILS))
  RtlZeroMemory_(mcdu,SizeOf(MIXERCONTROLDETAILS_UNSIGNED))
  
  result = mixerOpen_(@hMixer, 0, 0, 0, #MIXER_OBJECTF_HMIXER)
  If result = #MMSYSERR_NOERROR
    ml\cbStruct        = SizeOf(MIXERLINE)
    ml\dwComponentType = Type
    result = mixerGetLineInfo_(hMixer, @ml, #MIXER_GETLINEINFOF_COMPONENTTYPE)
    If result = #MMSYSERR_NOERROR
      mlc\cbStruct      = SizeOf(MIXERLINECONTROLS)
      mlc\dwLineID      = ml\dwLineID
      mlc\dwControlType = #MIXERCONTROL_CONTROLTYPE_VOLUME
      mlc\cControls     = 1
      mlc\pamxctrl      = @mc
      mlc\cbmxctrl      = SizeOf(MIXERCONTROL)
      result = mixerGetLineControls_(hMixer, @mlc, #MIXER_GETLINECONTROLSF_ONEBYTYPE)
      If result = #MMSYSERR_NOERROR
        mcd\cbStruct    = SizeOf(MIXERCONTROLDETAILS)
        mcd\dwControlID = mc\dwControlID;
        mcd\paDetails   = @mcdu
        mcd\cbDetails   = SizeOf(MIXERCONTROLDETAILS_UNSIGNED)
        mcd\cChannels   = 1
        result = mixerGetControlDetails_(hMixer, @mcd, #MIXER_SETCONTROLDETAILSF_VALUE)
        If result = #MMSYSERR_NOERROR
          dwVolume = mcdu\dwValue
        EndIf        
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn dwVolume  
EndProcedure

; newvolume va de 0 = 65535
Procedure MIXER_setVolume(Type.l, newvolume.l)
Protected ml.MIXERLINE, mlc.MIXERLINECONTROLS,mc.MIXERCONTROL,mcd.MIXERCONTROLDETAILS,mcdu.MIXERCONTROLDETAILS_UNSIGNED

  RtlZeroMemory_(ml,SizeOf(MIXERLINE))
  RtlZeroMemory_(mlc,SizeOf(MIXERLINECONTROLS))
  RtlZeroMemory_(mcd,SizeOf(MIXERCONTROLDETAILS))
  RtlZeroMemory_(mcdu,SizeOf(MIXERCONTROLDETAILS_UNSIGNED))
  
  result = mixerOpen_(@hMixer, 0, 0, 0, #MIXER_OBJECTF_HMIXER)
  If result = #MMSYSERR_NOERROR
    ml\cbStruct        = SizeOf(MIXERLINE)
    ml\dwComponentType = Type
    result = mixerGetLineInfo_(hMixer, @ml, #MIXER_GETLINEINFOF_COMPONENTTYPE)
    If result = #MMSYSERR_NOERROR
      mlc\cbStruct      = SizeOf(MIXERLINECONTROLS)
      mlc\dwLineID      = ml\dwLineID
      mlc\dwControlType = #MIXERCONTROL_CONTROLTYPE_VOLUME
      mlc\cControls     = 1
      mlc\pamxctrl      = @mc
      mlc\cbmxctrl      = SizeOf(MIXERCONTROL)
      result = mixerGetLineControls_(hMixer, @mlc, #MIXER_GETLINECONTROLSF_ONEBYTYPE)
      If result = #MMSYSERR_NOERROR
        mcdu\dwValue    = newvolume
        mcd\cbStruct    = SizeOf(MIXERCONTROLDETAILS)
        mcd\dwControlID = mc\dwControlID
        mcd\paDetails   = @mcdu
        mcd\cbDetails   = SizeOf(MIXERCONTROLDETAILS_UNSIGNED)
        mcd\cChannels   = 1
        result = mixerSetControlDetails_(hMixer, @mcd, #MIXER_SETCONTROLDETAILSF_VALUE)
        If result = #MMSYSERR_NOERROR
          ProcedureReturn #True
        Else
          ProcedureReturn #False
        EndIf
      EndIf
    EndIf
  EndIf
EndProcedure

Debug "Volume du micro   : " + Str(MIXER_getVolume(#MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE))
It isn't the good way but you can set the volume to 0 :)
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

And what will the user say when the song he is listening to "stops"? If you are 110% sure you want this, I think I've got a shorter way of doing it, but I don't think it's a good thing to do.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

@KarlLox, Thanks, Twelve points from the Norwegian jury :)
Post Reply