Re: [ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
Re: [ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
- Subject: Re: [ANN] ANSystemSoundWrapper - Cocoa wrapper for changing system volume
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 16 Apr 2008 10:06:10 +0200
Le 16 avr. 08 à 09:23, Antonio Nunes a écrit :
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
I don't want to start another "Code design" war, but just wonder if
doing "Utility Class" is a common practice in obj-c. Unlike Java or
other object oriented language, obj-c is a superset of C and support
simple functions. Wouldn't it be simpler to declare 4 functions
instead of 4 class methods ?
float ANGetSystemVolume();
void ANSetSystemVolume:(float volume);
..
_______________________________________________
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