I am using AVPlayer for a radio AVPlayer using HTTP streaming. Now I want to implement a level meter for this audio stream. The best thing is a level meter showing different frequencies, but a simple left / right solution will be a great starting point.
I found some examples using AVAudioPlayer . But I can not find a solution to get the necessary information AVPlayer .
Can anyone think of a solution to my problem?
EDIT I want to create something like this (but nicer)

EDIT II
It has been proposed to use MTAudioProcessingTap to obtain the original audio data. Examples that I could find using the array [[[_player currentItem] asset] tracks] , which, in my case, is an empty array. Another suggestion was to use [[_player currentItem] audioMix] , which is null for me.
EDIT III
After many years, a solution still does not exist. I really made progress, so I share it.
During installation, I add an observer with a key to the playerItem element:
[[[self player] currentItem] addObserver:self forKeyPath:@"tracks" options:kNilOptions context:NULL]; ////////////////////////////////////////////////////// - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)changecontext:(void *)context if ([keyPath isEqualToString:@"tracks"] && [[object tracks] count] > 0) { for (AVPlayerItemTrack *itemTrack in [object tracks]) { AVAssetTrack *track = [itemTrack assetTrack]; if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) { [self addAudioProcessingTap:track]; break; } } } - (void)addAudioProcessingTap:(AVAssetTrack *)track { MTAudioProcessingTapRef tap; MTAudioProcessingTapCallbacks callbacks; callbacks.version = kMTAudioProcessingTapCallbacksVersion_0; callbacks.clientInfo = (__bridge void *)(self); callbacks.init = init; callbacks.prepare = prepare; callbacks.process = process; callbacks.unprepare = unprepare; callbacks.finalize = finalise; // more tap setup... AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; AVMutableAudioMixInputParameters *inputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack]; [inputParams setAudioTapProcessor:tap]; [audioMix setInputParameters:@[inputParams]]; [[[self player] currentItem] setAudioMix:audioMix]; }
So far so good. All this works, I can find the desired track and configure the input parameters for Params and audioMix, etc. But unfortunately, the only callback that is called is the init callback. None of the others will shoot at any moment.
I tried different (types) of streaming sources, one of which is the official Apple HLS stream: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
ios objective-c avfoundation media-player avplayer
Julian F. Weinert Oct. 16 '13 at 12:35 on 2013-10-16 12:35
source share