Ante todo, te aclaro que lo que te estoy subiendo es un rejunte de código, que sería bueno que lo pruebes a fondo, se trata de una unit con una función genérica y dos implementaciones de esta, y un proyecto de ejemplo:
Código Delphi
[-]
unit MMUtils;
interface
uses
Windows;
procedure mmMixSetVolume(AComponentType, AValue: DWORD);
procedure mmMixSetMute(AComponentType: DWORD; AValue: boolean);
implementation
uses
SysUtils, MMSystem;
procedure RaiseLastMMError;
begin
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
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;
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.
El proyecto de ejemplo:
Código Delphi
[-]
program MMMixer;
uses
Windows, SysUtils, MMSystem,
MMUtils in '..\Comunes\MMUtils.pas';
begin
mmMixSetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, MaxWord div 2);
mmMixSetMute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, True);
end.
Saludos!