My mute program kills volume, but menubar doesn't show it
My mute program kills volume, but menubar doesn't show it
- Subject: My mute program kills volume, but menubar doesn't show it
- From: Gabriel Berriz <email@hidden>
- Date: Mon, 25 May 2009 22:21:54 -0400
Hi. I'm trying to mute the system volume in a way that is consistent
with the muting the user can do via the keyboard.
I found a way to mute the sound, like this:
void setSystemMute(UInt32 mute) {
OSStatus status;
AudioDeviceID device;
status = GetDefaultAudioDevice(&device); /* this function is
defined below */
require_noerr(status, ReturnStatus);
UInt32 size;
UInt32 channels[2];
size = sizeof(channels);
status =
AudioDeviceGetProperty(device, 0, false,
kAudioDevicePropertyPreferredChannelsForStereo,
&size, &channels);
require_noerr(status, ReturnStatus);
size = sizeof(mute);
for (int i = 0; i < 2; i++) {
status = AudioDeviceSetProperty(device, NULL, channels[i], false,
kAudioDevicePropertyMute, size, &mute);
require_noerr(status, ReturnStatus);
}
ReturnStatus:
return;
}
static OSStatus GetDefaultAudioDevice(AudioDeviceID *device) {
OSStatus status;
UInt32 size;
size = sizeof(*device);
status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultSystemDevice,
&size, device);
/* // I also tried:
status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice,
&size, device);
*/
return status;
}
Calling setSystemMute(1) does kill the volume, but this action does
not properly update the menu bar's volume indicator, or (apparently)
even the system's "mute state".
For example, executing this code silences the sound coming from the
machine, but information shown in System Preferences > Sound > Output
remains unchanged. In particular, the Mute checkbox remains
unchanged. Similarly, the volume icon on the menu bar remains
unchanged. If I hit the mute key at this point, the sound does not
come back on. I need to hit it a second time for the sound to finally
come back on.
I'd like to mute the system volume in such a way that (a) System
Preferences > Sound > Output and (if enabled) the menu bar indicate
that the volume is 0.0 and the mute is enabled; and (b) if the user
then hits the mute key again, the sound gets toggled back on.
Any suggestions about how to do this would be much appreciated.
TIA!
G.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden