Powered By Blogger

Tuesday, October 30, 2012

how to check iPhone volume programmatically?

Hi everyone,
Below is the trick to check the iPhone/iPad/iPod Touch (iOS Device) volume level. Please take a look..

#import <AudioToolbox/AudioToolbox.h>

    Float32 volume;
    UInt32 dataSize = sizeof(Float32);
    AudioSessionGetProperty (
                             kAudioSessionProperty_CurrentHardwareOutputVolume,
                             &dataSize,
                             &volume
                             );
    NSLog(@"Volume Level : %f",volume);
    if (volume <= 0.25)
    {
              NSLog(@"Volume is below %d \%",(volume*100));
    }

Thanks,
Nilesh M. Prajapati

1 comment: