user1470393
user1470393

Reputation: 327

audioSessionGetProperty doesn't work (iOS)

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.

Upvotes: 0

Views: 655

Answers (1)

Bart van Kuik
Bart van Kuik

Reputation: 4862

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

Example:

AudioSessionInitialize(NULL, NULL, NULL, (__bridge void*)self);

Upvotes: 0

Related Questions