Under OSX programmatically control the master volume as well as register the volume change notification.
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LXVolumeController.xcodeproj
LXVolumeController
README.md

README.md

LXVolumeController

Volume Control

Under OSX programmatically control the master volume as well as register the volume change notification.

##The API header file

#ifndef LXMasterVolume_h
#define LXMasterVolume_h

//set master volume
void setMasterVolume(CGFloat volume);//0.0~1.0

//get master volume
CGFloat getMasterVolume();//0.0~1.0

//volume change notification name is LXMasterVolumeChangedNotification
//[[NSNotificationCenter defaultCenter] addObserver:self
//                                         selector:@selector(volumeChanged:)
//                                             name:@"LXMasterVolumeChangedNotification"
//                                           object:nil];
//to get volume change notification
void startMasterVolumeChangeNotification();
void stopMasterVolumeChangeNotification();

#endif

##Get the system volume

CGFloat volume=getMasterVolume();//range 0.0~1.0 

##Set the system volume

setMasterVolume(volume);//range 0.0~1.0 

##Get volume change notification

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(volumeChanged:)
                                                 name:@"LXMasterVolumeChangedNotification"
                                               object:nil];
    startMasterVolumeChangeNotification();
}

- (void)volumeChanged:(NSNotification*)n
{
    CGFloat volume=getMasterVolume();
    //volume changed
}

##Stop volume change notification

stopMasterVolumeChangeNotification();  
[[NSNotificationCenter defaultCenter] removeObserver:self
												name:@"LXMasterVolumeChangedNotification"
											  object:nil];