views:

425

answers:

2

I am trying to get a UISlider to sync with the volume rocker. I have successfully used the slider to change the system/ringer volume, but I need the slider to move when the rocker moves. any suggestions on how to get the current volume value? I am using the code below to monnitor the volume change:

- (void)volumeChanged:(NSNotification *)notification{

       AVSystemController* avc = SharedAVSystemController;
       //   my sliders name is customVolume, and this is how I 
       //   am trying to get the volume:
       customVolume.value = [avc getVolume:(float *) forCategory:(id)];

}

Also, what are the AVSystemController categories other than "Ringtone"?

A: 

There is a class available in the SDK which handles the system volume all by itself, MPVolumeView. It's not a subclass of UISlider therefore you can't change it's appearance (Well, it would be hard hacking it together all by yourself) but that's probably not an issue. (edit: looking at class dumps, the view contains a normal UISlider view so it may be easier than I expected)

I'm not sure whether it handles everything you need and if it will fit in your context, but you can also take a look at it and try it.

JoostK
I just answered my own question, second, Im not going to be using the MPVolumeView as I'm interested in chaging the system volume, not just Media volumes ;P I <3 private frameworks!
AWright4911
Apple doesn't, that's always the problem. I have used a lot of private methods, just to make my app only _look_ Apple-ish. I just need to overwrite private methods or it will look not like other iPhone apps (The Maps.app table alert view as example), I hope Apple will understand. Good luck!
JoostK
Well, I really hope that they will start allowing more private methods, it seems with every new SDK, they are making more frameworks private! Pretty soon, ALL frameworks are going to be private, and there will be no more Apple Developer Program!!!
AWright4911
A: 

This will update theUISlider with the volume rocker:

- (void)volumeChanged:(NSNotification *)notification
{
    AVSystemController *avs = [ notification object ];
    NSString *audioDeviceName;
    [ avs getActiveCategoryVolume:&_volume
                       andName:&audioDeviceName ];

}
AWright4911