Search code examples
objective-cavaudioplayermetering

AVAudioPlayer meter values still - 160


Trying to implement AVAudioplayer and get some metering data of the played music, but still getting value -160. It looks easy to use, just enable Meter and then pickup data under a timer, but no results so far.

playerAV = [[AVAudioPlayer alloc] initWithContentsOfURL:outURL error:nil];
        playerAV.delegate = self;


        playerAV.meteringEnabled = YES;

        [playerAV prepareToPlay];
        [playerAV play];

NSLog(@"Peak left: %f Avg right: %f", [playerAV peakPowerForChannel:0],[playerAV averagePowerForChannel:1]);

any thoughts are welcome.


Solution

  • Are you calling updateMeters? The docs for both peakPowerForChannel: and averagePowerForChannel: say:

    To obtain a current [...] value, you must call the updateMeters method before calling this method.