4

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.

Community
  • 1
  • 1
Vidhi
  • 2,026
  • 2
  • 20
  • 31
  • I came to know that above code returns player volume, not phone's ringer volume. I referred many post from stack overflow but most of them provide solution to get music player volume. Please i want to know if it is possible to get **phone's ringer** volume ( not player volume) using ios programming ? – Vidhi May 07 '14 at 12:56

1 Answers1

3

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
}
nmh
  • 2,497
  • 1
  • 15
  • 27
  • I can set NSNotification and check volume when sound change but my application make phone silent when specified event occurs ( that is client set any event for specific time ) and make phone in general mode when that event ends. After 15 minutes of event end i want to check if phone is in silent mode? if yes i want to send notification to user that phone is still in silent mode. So i need to check without setting NSNotification – Vidhi May 08 '14 at 13:46
  • Hey thank you for suggestion. I set NSNotification and in volumeChanged method i set volume in NSUserDefaults. And when my event get end, after 15 min, i get this NSUserDefaults and it worked... Thanks again – Vidhi May 09 '14 at 14:15
  • Not run with IOS 10 beta – vualoaithu Aug 03 '16 at 09:09