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],[pla开发者_如何学JAVAyerAV averagePowerForChannel:1]);
any thoughts are welcome.
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.
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()?
精彩评论