0

I am trying to detect the current volume, but the result is always 0. this is my codes:

in the view controller.m

  1. import the AudioToolbox.

  2. in viewDidLoad method, AudioSessionInitialize(NULL, NULL, NULL, NULL);

  3. in viewDidLoad method, following the above initialization method.

      Float32 volume_reading;
    

    UInt32 dataSize = sizeof(Float32);

    AudioSessionGetProperty ( kAudioSessionProperty_CurrentHardwareOutputVolume, &dataSize, &volume_reading );

  4. po volume_reading in the debugger, result is 0.

Any suggestion? Thanks very much.

user1470393
  • 317
  • 4
  • 12

1 Answers1

0

This is a somewhat older question, but did you initialize the audio session?

Example:

AudioSessionInitialize(NULL, NULL, NULL, (__bridge void*)self);
Bart van Kuik
  • 4,704
  • 1
  • 33
  • 57