Is there any way to subscribe to volume buttons press events?
When you're on the phone or listening to songs, movies, or other media on iPhone, you can use the buttons on the side of your device to adjust the audio volume. Otherwise, the buttons control the volume for the ringer, alerts, and other sound effects. You can also use Siri to turn the volume up or down.
After the recent rejections from Apple
Do not use this. Apple now uses some patch which would reject your app straightaway if it uses any of the private APIs - though should note here that quite some apps on the App Store use this already and are still there!
The only way to do this now is to have an AVAudioPlayer prepared to play but not playing ([player prepareToPlay]). This seems to take care of adjusting the app's volume according to the rocker buttons.
There's no other published way currently to handle this.
PLEASE READ THE ABOVE NOTE
Yes, Use the MPVolumeView
MPVolumeView *volume = [[[MPVolumeView alloc] initWithFrame:CGRectMake(18.0, 340.0, 284.0, 23.0)] autorelease]; [[self view] addSubview:volume]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil]; for (UIView *view in [volume subviews]){ if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) { volumeViewSlider = view; //volumeViewSlider is a UIView * object } } [volumeViewSlider _updateVolumeFromAVSystemController]; -(IBAction)volumeChanged:(id)sender{ [volumeViewSlider _updateVolumeFromAVSystemController]; }
This will give you a slider (same as one used in ipod) whose value will change acc to volume of the phone
You will get a compile-time warning that view may not respond to _updateVolumeFromAVSystemControl, but just ignore it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With