Skip navigation.
 
mlRe: Mute System
FROM : Keith Duncan
DATE : Wed Mar 12 23:41:23 2008

> what i have to do to control the system Aduio Volume (mute, 
> increase, decrease).


I use CoreAudio; AppleScript is too inefficient for my uses.

static OSStatus GetDefaultAudioDevice(AudioDeviceID *device) {
   OSStatus status;
   
   UInt32 size;
    size = sizeof(*device);
    status = 
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, 
&size, device);
   
   return status;
}

- (void)setSystemVolume:(NSUInteger)volume {
   OSStatus status;
   
   AudioDeviceID device;
   status = GetDefaultAudioDevice(&device);
   require_noerr(status, ReturnStatus);
   
   UInt32 size;
   
   UInt32 channels[2];
    size = sizeof(channels);
    status = AudioDeviceGetProperty(device, 0, false, 
kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
   require_noerr(status, ReturnStatus);
   
   UInt32 mute = (volume == 0);
   float systemVolume = volume/100.0;
   
   for (NSUInteger index = 0; index < 2; index++) {
       size = sizeof(mute);
       status = AudioDeviceSetProperty(device, NULL, channels[index], 
false, kAudioDevicePropertyMute, size, &mute);
       require_noerr(status, ReturnStatus);
       
       size = sizeof(systemVolume);
       status = AudioDeviceSetProperty(device, NULL, channels[index], 
false, kAudioDevicePropertyVolumeScalar, size, &systemVolume);
       require_noerr(status, ReturnStatus);
   }
   
ReturnStatus:
   
   return;
}

Related mailsAuthorDate
mlMute System Herr Thomas Bartel… Mar 12, 19:49
mlRe: Mute System I. Savant Mar 12, 20:23
mlRe: Mute System Jean-Daniel Dupas Mar 12, 20:31
mlRe: Mute System Keith Duncan Mar 12, 23:41
mlRe: Mute System Christopher Nebel Mar 13, 05:10
mlRe: Mute System I. Savant Mar 13, 11:58