Reputation: 11689
I know a lot of people asked this but I didn't read any answer, are there any lib/a generic way to GET (not set, I don't need it) the master volume (the volume of the current source of output for sounds, not voice) which works for both xp/vista/seven ?
If not, how to do it for xp, vista, seven (I'll write my generic wrapper)
I need to show a bar (progress bar) to show how is set the current volume (winform control)
Edit:
I found a useful link, I'm testing it but I won't check the answer 'till I get something that works http://www.codeproject.com/KB/audio-video/mixerSetControlDetails.aspx?display=Print
Edit 2:
An important thing: the previous way to analyze volume won't work on windows vista or later, use this lib instead: http://www.codeproject.com/KB/vista/CoreAudio.aspx
I don't know if really works well because I don't have vista/seven at the moment
Upvotes: 0
Views: 3191
Reputation: 210352
Does mixerGetNumDevs and the related API help? (You have to go through all the devices with mixerGetLineControls
, etc. and see which MIXERCONTROL
says "Volume" for the name; there's also a way to check the flag. That's the one you're looking for.)
Edit:
Here's a snippet of some old code I had; I don't think it compiles, and it's not great code (I just needed to get stuff done), but it should be helpful:
MMRESULT mmResult = mixerOpen(&hMixer, 0, (DWORD_PTR)hWnd, NULL, CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
if (MMSYSERR_NOERROR == mmResult)
{
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
MMRESULT mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
if (mmResult == MMSYSERR_NOERROR)
{
MIXERLINECONTROLS controls;
memzero(&controls, sizeof(controls));
controls.cbStruct = sizeof(controls);
controls.cControls = 1;
controls.dwLineID = mxl.dwLineID;
controls.cbmxctrl = sizeof(MIXERCONTROL); //one element only!!
MIXERCONTROL controlsArray[2]; //First element: volume, second element: mixer
memzero(&controlsArray, sizeof(controlsArray));
for (int i = 0; i < sizeof(controlsArray) / sizeof(*controlsArray); i++) { controlsArray[0].cbStruct = sizeof(controlsArray[0]); }
controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
controls.pamxctrl = &controlsArray[0]; //NOTE: this is ZERO
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
controls.pamxctrl = &controlsArray[1]; //NOTE: this is ONE
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
bool isVolume = controls[0].dwControlID == (DWORD)lParam;
bool isMute = controls[1].dwControlID == (DWORD)lParam;
if (isVolume | isMute)
{
MIXERCONTROLDETAILS details;
memzero(&details, sizeof(details));
details.cbStruct = sizeof(details);
details.cChannels = 1;
details.dwControlID = (DWORD)lParam;
MIXERCONTROLDETAILS_UNSIGNED controlDetail;
memzero(&controlDetail, sizeof(controlDetail));
details.paDetails = &controlDetail;
details.cbDetails = sizeof(controlDetail);
MMRESULT mmResult = mixerGetControlDetails((HMIXEROBJ)hMixer, &details, MIXER_GETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
if (mmResult == MMSYSERR_NOERROR)
{
}
}
}
}
}
}
Upvotes: 1