Re: My mute program kills volume, but menubar doesn't show it
Re: My mute program kills volume, but menubar doesn't show it
- Subject: Re: My mute program kills volume, but menubar doesn't show it
- From: Jeff Moore <email@hidden>
- Date: Tue, 26 May 2009 13:10:20 -0700
Most likely, this means that you have one of our more recent bits of
hardware. The newer hardware has a master mute control in addition to
the per-channel mute controls. It appears from empirical testing that
the menu bar widget and the Sound Prefs panel both use the global mute
control to inform the UI state.
Since your code is not manipulating the master mute control (aka
channel 0), just the individual channel mutes, the UI is not updating.
The fix for this is quite simple, just add a call to set the
kAudioDevicePropertyMute on channel 0.
On May 25, 2009, at 7:21 PM, Gabriel Berriz wrote:
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.
_______________________________________________
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