[ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
[ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
- Subject: [ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
- From: Antonio Nunes <email@hidden>
- Date: Wed, 16 Apr 2008 08:23:18 +0100
Hi,
I've put together a simple wrapper to easily change the system sound
volume using Objective-C, obviating the need to deal directly with
lower-level CoreAudio calls.
The files are available here: http://sintraworks.com/media/code/ANSystemSoundWrapper.zip
The wrapper consists of a single class that implements three class
methods to affect the system sound volume level, and a single class
method to get the current level:
+ (float)getSystemVolume;
+ (void)setSystemVolume:(float)inVolume;
+ (void)increaseSystemVolumeBy:(float)amount;
+ (void)decreaseSystemVolumeBy:(float)amount;
To use it you need to link against the CoreAudio framework and include
the header file in any implementation file where you want to call any
of the above methods. The code is distributed under the MIT license,
so you can do pretty much anything you want with it. Any comments on
the code always appreciated.
The sample below uses a timer to trigger periodical changes to the
sound volume, and will play a sound to feed the new volume back, as
long as there is an actual change in level (i.e. until the max or min
sound level has been reached, either 0 or 1):
- (void)increaseSystemVolume:(NSTimer*)timer
{
float oldVol = [ANSystemSoundWrapper getSystemVolume];
[ANSystemSoundWrapper increaseSystemVolumeBy:.05];
if (oldVol != [ANSystemSoundWrapper getSystemVolume]) {
[[NSSound soundNamed:@"Tink"] play];
}
}
- (void)decreaseSystemVolume:(NSTimer*)timer
{
float oldVol = [ANSystemSoundWrapper getSystemVolume];
[ANSystemSoundWrapper decreaseSystemVolumeBy:.05];
if (oldVol != [ANSystemSoundWrapper getSystemVolume]) {
[[NSSound soundNamed:@"Tink"] play];
}
}
-António
----------------------------------------------------
Energy is like a muscle,
it grows stronger through being used.
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden