Vanya
Vanya

Reputation: 5005

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.

Upvotes: 2

Views: 683

Answers (2)

Tom Andersen
Tom Andersen

Reputation: 7200

How do you know the url works, and the data at the end of it is the right format? Can you hear stuff coming from the speakers?

Are you somehow making two playerAV objects, one with the correct URL which plays, the other with a bad url which plays nothing, and is the one that the timer sees when it calls NSLog()?

Upvotes: 1

jscs
jscs

Reputation: 64002

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.

Upvotes: 2

Related Questions