According to https://developer.apple.com/documentation/avfoundation/avplayer/1388027-addboundarytimeobserver I can observe to specified times that are traversed during playback.
func addBoundaryTimeObserver(forTimes times: [NSValue],queue: DispatchQueue?,using block: @escaping () -> Void) -> Any
And then there's example of how to detect times for each quarter of playback passed
func addBoundaryTimeObserver() {
var times = [NSValue]()
// Set initial time to zero
var currentTime = kCMTimeZero
// Divide the asset's duration into quarters.
let interval = CMTimeMultiplyByFloat64(asset.duration, 0.25)
// Build boundary times at 25%, 50%, 75%, 100%
while currentTime < asset.duration {
currentTime = currentTime + interval
times.append(NSValue(time:currentTime))
}
// Queue on which to invoke the callback
let mainQueue = DispatchQueue.main
// Add time observer
timeObserverToken = player.addBoundaryTimeObserver(forTimes: times,
queue: mainQueue) {
// Update UI
}
}
But how do I get which time from times array exactly was passed, so that I can know which quartile has passed?