behindOf function
How far position is behind the live edge of a window, or null when it
is close enough to the edge to count as live.
Returns null (i.e. "at the edge") when the window is unknown/zero, when
the gap is within edgeThreshold, or when position sits at or past the
window end — a playhead ahead of the window is a clock-skew artefact, not a
negative time-shift.
返回 position 落后 window 直播边缘的时长;足够接近边缘时返回 null。
以下三种情况都返回 null(即"在边缘"):窗口未知/为零;差距在
edgeThreshold 以内;position 位于窗口末端或之后——播放头跑到窗口前面
是时钟偏差造成的假象,不是负的时移量。
position: current playhead within the window / 窗口内的当前播放位置window: seekable window length / 可拖动窗口长度edgeThreshold: gap still counted as live / 仍算作直播的差距阈值
Returns the lag, or null when at the edge / 返回落后时长;在边缘时返回 null。
Implementation
Duration? behindOf(Duration position, Duration window, Duration edgeThreshold) {
if (window <= Duration.zero) return null;
final behind = window - position;
if (behind <= edgeThreshold) return null;
return behind;
}