1. First listen to the Playeritem
[Playeritem addobserver:self forkeypath:@ "Playbackbufferempty" Options:nskeyvalueobservingoptionnew Context:nil];
[Playeritem addobserver:self forkeypath:@ "Playbacklikelytokeepup" Options:nskeyvalueobservingoptionnew Context:nil ];
2. In the Listening method
-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object
Change: (nsdictionary *) Change context: (void *) Context {
if (!player)
{
Return
}
else if (object = = Playeritem && [keypath isequaltostring:@ "Playbackbufferempty"])
{
if (playeritem.playbackbufferempty) {
Do some buffering operations such as displaying a label or loading a buffer bar playbufferempty (to identify whether it is buffered)
Playbufferempty = TRUE;
[Indicator startanimating];
[Vidstreaminglabel settext:@ "buffering ..."];
[Vidstreaminglabel Sethidden:no];
}
}
Else if (object = = Playeritem && [keypath isequaltostring:@ "Playbacklikelytokeepup"])
{
if (playerite M.playbacklikelytokeepup)
{
//Do some end buffering operation
Playbufferempty = FALSE;
[Indicator stopanimating];
[Vidstreaminglabel Sethidden:yes];
}
}
}
On the handling of Avplayer buffering problem