AVPlayer
primarily measures times with CMTime
. However when using an AVPlayerItemMetadataCollector
to collect date range metadata from an HLS stream, the resulting AVDateRangeMetadataGroup
s hold NSDate
s instead of CMTime
s.
My problem is I want to add a boundary time observer to the player so I know when the playback head actually enters the date range, but you can only add a boundary time observer using CMTime
. AVPlayer
and AVPlayerItem
can seek to a Date
and can give me the current playback head as a Date
, but I don't see any way to convert a given Date
into a CMTime
that I can use to set a boundary time observer.
In theory if I knew what the EXT-X-PROGRAM-DATE-TIME
tag said I could calculate a CMTime
offset myself, but I don't see a way to retrieve that.
The only other thought I had was to retrieve both currentTime
and currentDate
from the AVPlayerItem
, then calculate the relative offset between currentDate
and my target date and apply that to the CMTime
. But a problem with this solution is the currentDate
and currentTime
won't represent the exact same time. The delta is presumably going to be very small, but it won't be zero (unless the rate
itself is zero).