스트림 내용을 재생하는 AVPlayer를 사용합니다. 버퍼가 비어있는 시간과 재생할 준비가 된 시간을 알고 싶습니다. 그러나 observer "playbackBufferEmpty"및 "playbackLikelyToKeepUp"은 필요에 따라 매번 작동하지 않습니다. 때로는 효과가 있지만 종종 효과가 없습니다. OSX 10.7.5에서 iPad 시뮬레이터 iOS 6.1 만 사용합니다.AVPlayer 항목 버퍼가 비어 있음
- (void)playAudioStream:(NSURL *)audioStreamURL
{
if(_audioPlayer && _audioPlayer.currentItem)
{
[_audioPlayer removeObserver:self forKeyPath:StatusKey];
[_audioPlayer.currentItem removeObserver:self forKeyPath:@"playbackBufferEmpty"];
[_audioPlayer.currentItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
}
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:audioStreamURL];
[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
_audioPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[_audioPlayer addObserver:self forKeyPath:StatusKey options:NSKeyValueObservingOptionNew context:nil];
//[_audioPlayer replaceCurrentItemWithPlayerItem:playerItem];
//_audioPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[_audioPlayer play];
}
...
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"playbackBufferEmpty"])
{
if (_audioPlayer.currentItem.playbackBufferEmpty)
{
...
}
}
if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"])
{
if (_audioPlayer.currentItem.playbackLikelyToKeepUp)
{
...
}
}
}
얻을 "빈 버퍼"를 (인터넷 연결이 끊어 때, 예를 들어) 이벤트 "준비를 버퍼링"올바른 방법으로 나를 도와주세요 : 내가 관찰자를 설정하고 듣는 방법은 다음과 이다. 고맙습니다!