Question

How can i get iphone's current ringer volume level using AVSystemController

I also tried below code to check volume level

MPVolumeView *slide = [MPVolumeView new];
UISlider *volumeViewSlider;

for (UIView *view in [slide subviews]){
    if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
        volumeViewSlider = (UISlider *) view;
    }
}
float val = [volumeViewSlider value];

But when i print / check val, it returns 1.00

I also tried below code

musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
Nslog(@"%f",musicPlayer.volume);

But it also returns 1.00 event if my phone is silent. I refer below link How to determine the current level of the iPhone ringer? but i could not find solution.

Please help.

Was it helpful?

Solution

Try this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(volumeChanged:)
                                             name:@"AVSystemController_SystemVolumeDidChangeNotification"
                                           object:nil];

- (void)volumeChanged:(NSNotification *)notification{
   NSDictionary*dict=notification.userInfo;
   float newVolume =
   [[dict objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]floatValue];
    //my comment: newVolume is value that you need
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top