user2168735
user2168735

Reputation: 489

How to get System Volume iOS?

I found an example here, but it does not work on ios6.1.3 (iphone 4s). always return 0.187500

Code:

Float32 volume;
UInt32 dataSize = sizeof(Float32);

AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionGetProperty (
                     kAudioSessionProperty_CurrentHardwareOutputVolume,
                     &dataSize,
                     &volume
                     );
NSLog(@"%f", volume);

[AVAudioSession sharedInstance].outputVolume - also return 0.187500

Upvotes: 3

Views: 4515

Answers (2)

akanki07
akanki07

Reputation: 71

float volume = [[AVAudioSession sharedInstance] outputVolume];

Upvotes: 4

Hampus Nilsson
Hampus Nilsson

Reputation: 6822

You need to initialize the audio session with:

AudioSessionInitialize (NULL, NULL, NULL, NULL);

in viewDidLoad or similar.

However, it's generally a better idea to make use of the new AVAudioSession class if you're targeting iOS 6+, which handles that for you:

float volume = [AVAudioSession sharedInstance].outputVolume;

Upvotes: 4

Related Questions