AVPlayer를 사용하여 라이브 오디오 스트림을 스트리밍하는 응용 프로그램에 미터 그래프를 표시하려고합니다. peakPowerForChannel
AVPlayer 라이브 스트림 오디오 레벨 미터링에 전원을 공급하는 방법
를 사용하지만 AVAudioPlayer 오디오 스트림이 작동하지 않습니다 Trying to understand AVAudioPlayer and audio level metering
: 나는 AVAudioPlayer 알고
는 방법에 따라이있다.
AVPlayer와 비슷한 것이 있습니까? 아니면 AVPlayer에서 전력 값을 얻을 수있는 다른 방법이 있습니까?
코드 : 일반적으로
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
if (self.avplayer) {
[self.avplayer replaceCurrentItemWithPlayerItem:nil];
}
AVURLAsset *avAsset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:@"http://broadcast.infomaniak.net/radionova-high.mp3"] options:nil];
NSArray *keys = @[@"playable"];
[avAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
AVPlayerItem *newItem = [[AVPlayerItem alloc] initWithAsset:avAsset];
if (!self.avplayer) {
self.avplayer = [[AVPlayer alloc] initWithPlayerItem:newItem];
} else {
[self.avplayer replaceCurrentItemWithPlayerItem:newItem];
}
[self.avplayer addObserver:self forKeyPath:@"status" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
[self.avplayer addObserver:self forKeyPath:@"rate" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
});
}];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
NSLog(@"%@ called",keyPath);
if ([keyPath isEqualToString:@"status"]) {
[self.avplayer play];
} else if ([keyPath isEqualToString:@"rate"]) {
if (self.avplayer.rate) {
NSLog(@"Playing...");
[[NSNotificationCenter defaultCenter] postNotificationName:@"currentPlayingChangedToPlay" object:nil];
} else {
NSLog(@"Not playing...");
[[NSNotificationCenter defaultCenter] postNotificationName:@"currentPlayingChangedToPause" object:nil];
}
}
}
다음을 확인하십시오. https://github.com/akhilcb/ACBAVPlayerExtension – adev