Ir al contenido


Foto

Subir y Bajar Volumen


  • Por favor identifícate para responder
4 respuestas en este tema

#1 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 260 mensajes

Escrito 19 noviembre 2012 - 10:18

Buenas chicos, como les va, vengo con una nueva interrogante a suplicarles su ayuda.....
Como dice el título estoy deseando saber la manera de como Subir y bajar el volumen del sistema Windows, por ahí encontré este pedacito de código:


delphi
  1. uses MMSystem;
  2.  
  3. type
  4.   TVolumeRec = record
  5.     case Integer of
  6.       0: (LongVolume: Longint) ;
  7.       1: (LeftVolume, RightVolume : Word) ;
  8.     end;
  9.  
  10. const DeviceIndex=5
  11.       {0:Wave
  12.         1:MIDI
  13.         2:CDAudio
  14.         3:Line-In
  15.         4:Microphone
  16.         5:Master
  17.         6:PC-loudspeaker}
  18.    
  19. procedure SetVolume(aVolume:Byte) ;
  20. var Vol: TVolumeRec;
  21. begin
  22.   Vol.LeftVolume := aVolume shl 8;
  23.   Vol.RightVolume:= Vol.LeftVolume;
  24.   auxSetVolume(UINT(DeviceIndex), Vol.LongVolume) ;
  25. end;
  26.  
  27. function GetVolume:Cardinal;
  28. var Vol: TVolumeRec;
  29. begin
  30.   AuxGetVolume(UINT(DeviceIndex),@Vol.LongVolume) ;
  31.   Result:=(Vol.LeftVolume + Vol.RightVolume) shr 9;
  32. end;



Tiene buena pinta pero no logro implementarlo en Lazarus, haber si me dan una manito....... :)
  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.108 mensajes
  • LocationMadrid - España

Escrito 20 noviembre 2012 - 12:43

Este volumen te puede resultar interesante.


Este código funciona en Lazarus. Los valores de volumen van de 0 a 65535


delphi
  1. uses
  2.   Windows, MMSystem;
  3.  
  4. ....................................
  5.  
  6.  
  7. function GetControl(Mixer: DWORD; Control: LPMIXERCONTROL; CtlType: DWORD): DWORD;
  8. var
  9.   Line: MIXERLINE;
  10.   Controls: MIXERLINECONTROLS;
  11. begin
  12.   ZeroMemory(@Line, sizeof(Line));
  13.   ZeroMemory(@Controls, sizeof(Controls));
  14.   Line.cbStruct:= sizeof(Line);
  15.   Line.dwComponentType:= MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
  16.   Result:= mixerGetLineInfo(Mixer, @Line, MIXER_GETLINEINFOF_COMPONENTTYPE);
  17.   if Result = MMSYSERR_NOERROR then
  18.   begin
  19.     Controls.cbStruct:= sizeof(Controls);
  20.     Controls.dwLineID:= Line.dwLineID;
  21.     Controls.cControls:= 1;
  22.     Controls.dwControlType:= CtlType;
  23.     Controls.cbmxctrl:= sizeof(MIXERCONTROL);
  24.     Controls.pamxctrl:= Control;
  25.     Result:= mixerGetLineControls(Mixer, @Controls, MIXER_GETLINECONTROLSF_ONEBYTYPE);
  26.   end;
  27. end;
  28.  
  29.  
  30. function SetMasterVolume(Mixer: HMIXEROBJ; Value: DWORD): DWORD;
  31. var
  32.   MasterVolume: MIXERCONTROL;
  33.   Details: TMIXERCONTROLDETAILS;
  34.   UnsignedDetails: MIXERCONTROLDETAILS_UNSIGNED;
  35. begin
  36.   ZeroMemory(@Details, sizeof(Details));
  37.   Result:= GetControl(0, @MasterVolume, MIXERCONTROL_CONTROLTYPE_VOLUME);
  38.   if Result = MMSYSERR_NOERROR then
  39.   begin
  40.     Details.cbStruct:= sizeof(MIXERCONTROLDETAILS);
  41.     Details.dwControlID:= MasterVolume.dwControlID;
  42.     Details.cChannels:= 1;
  43.     Details.cMultipleItems:= 0;
  44.     Details.cbDetails:= sizeof(MIXERCONTROLDETAILS_UNSIGNED);
  45.     Details.paDetails:= @UnsignedDetails;
  46.     UnsignedDetails.dwValue:= Value;
  47.     Result:= mixerSetControlDetails(Mixer, @Details, MIXER_SETCONTROLDETAILSF_VALUE);
  48.   end;
  49. end;
  50.  
  51. function GetMasterVolume(Mixer: HMIXEROBJ; Value: LPDWORD): DWORD;
  52. var
  53.   MasterVolume: MIXERCONTROL;
  54.   Details: TMIXERCONTROLDETAILS;
  55.   UnsignedDetails: MIXERCONTROLDETAILS_UNSIGNED;
  56. begin
  57.   Value^:= 0;
  58.   Result:= GetControl(0, @MasterVolume, MIXERCONTROL_CONTROLTYPE_VOLUME);
  59.   if Result = MMSYSERR_NOERROR then
  60.   begin
  61.     Details.cbStruct:= sizeof(MIXERCONTROLDETAILS);
  62.     Details.dwControlID:= MasterVolume.dwControlID;
  63.     Details.cChannels:= 1;
  64.     Details.cMultipleItems:= 0;
  65.     Details.cbDetails:= sizeof(MIXERCONTROLDETAILS_UNSIGNED);
  66.     Details.paDetails:= @UnsignedDetails;
  67.     mixerGetControlDetails(Mixer, @Details, MIXER_SETCONTROLDETAILSF_VALUE);
  68.   end;
  69.   Value^:= UnsignedDetails.dwValue;
  70. end;                             

Saludos.


  • 0

#3 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 260 mensajes

Escrito 20 noviembre 2012 - 02:47

Gracias escafranda por su ayuda, mas como implementaría su respectiva llamada.... ???
:)
  • 0

#4 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.108 mensajes
  • LocationMadrid - España

Escrito 20 noviembre 2012 - 02:59

Para ajustar un volumen (entre 0 y 65535)


delphi
  1. SetMasterVolume(0, 20000);



Para conocer el volumen:


delphi
  1. var
  2.   Vol: DWORD;
  3. begin
  4.   GetMasterVolume(o, @Vol);
  5. end;




Saludos.
  • 0

#5 monchito_elroro

monchito_elroro

    Advanced Member

  • Miembros
  • PipPipPip
  • 260 mensajes

Escrito 10 diciembre 2012 - 10:31

Gracias amigo, me tome tiempo para probarlo en windows xp, y si funciona, aún no lo pruebo en windows 7, pero tuve la oportunidad de probarlo en windows 8 y en este sistema no obecede...... Será por ser nuevo....?

Seguiré probandolo y de ahí les aviso...  :)
  • 0




IP.Board spam blocked by CleanTalk.