addBoundaryTimeObserver not firing

For a LIVE HLS asset, EXT-X-DATERANGE objects are being inserted with important time values that are relative to the players current time.


For each AVDateRangeMetadataGroup received I want to create a boundary time observer.


Essentially I set my view as a


AVPlayerItemMetadataCollectorPushDelegate


and within the function


metadataCollector(_ metadataCollector: AVPlayerItemMetadataCollector, didCollect metadataGroups: [AVDateRangeMetadataGroup], indexesOfNewGroups: IndexSet, indexesOfModifiedGroups: IndexSet)


I look through each AVDateRangeMetadataGroup found, parse the desired time value from its items array and add to a stored array.


let times = [NSValue]()
for metadata in metadataGroups {
     for item in metadata.items {
         ... <create CMTime>
          times.append(NSValue(time: CMTime.seconds))
     }
}


Since the documentation says Each invocation of this method should be paired with a corresponding call to

removeTimeObserver:
.


I then call removeTimeObserver


if let bto = boundaryTimeObserver {
     avPlayer?.removeTimeObserver(bto)
      boundaryTimeObserver = nil
}


Finally I add all my times to the boundaryTimeObserver


boundaryTimeObserver = avPlayer?.addBoundaryTimeObserver(forTimes: times, queue: .main, using: { [weak self] in ... }


Since this a live stream typically I have about 3 fragment durations time between when the DATERANGE is parsed and the expected time the boundaryTimeObserver is fired. In my case with 6 second fragments this is ~18 seconds. However inconsistencies in network traffic and how close I am to the edge of the live point this number could be very small.


Now lets assume the scenario there is a start daterange and an end daterange tag inserted with relative playhead start and end times that I want to know about. What I find that with the above method only the start times are ever fired and the end times are missed, even when they are clearly added to the observer 15 seconds before the expected time to fire.


An example set of logs is


> Start Event-1 Boundary Time: 20705.057
> Adding 1 boundary time observer

~15 seconds pass

> Boundary Time Observed at time: 20705.058508673

~90 seconds pass

> Start Event-1 Boundary Time: 20705.057
> End Event-1 Boundary Time: 20810.118
> Adding 2 boundary time observers


Playhead now passes End Event-1 Boundary Time without the block being fired.


So my questions is:


1. Does my approach sound logical? I think because of the way I remove the observer and add a new observer with a larger number of times might not be an intended use case.


I know the documentation says "The player does not guarantee the callback block will always be invoked for each boundary time. If your times are very close together along the timeline (close enough that the execution of the block for one takes longer than the difference between them) or if a seek causes time to jump over one or more boundary times, time observation for any specific boundary time may not occur." However I can assure that there is no time jump (unless discontinuity tags are creating some weird behavior regarding time jumps as each daterange is associated with one), there are large differences between times, and the executing code is a simple log so it no way should it be causing any delay in executions.


I also want to note that the documentation found at https://developer.apple.com/documentation/avfoundation/avplayer/1388027-addboundarytimeobserver is outdated or something as the callback block does not have time parameter associated with it.