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;
}
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 mails | Author | Date |
|---|---|---|
| Herr Thomas Bartel… | Mar 12, 19:49 | |
| I. Savant | Mar 12, 20:23 | |
| Jean-Daniel Dupas | Mar 12, 20:31 | |
| Keith Duncan | Mar 12, 23:41 | |
| Christopher Nebel | Mar 13, 05:10 | |
| I. Savant | Mar 13, 11:58 |






Cocoa mail archive

