google/ExoPlayer

How to get the live latency?

mehdibf opened this issue · 2 comments

[REQUIRED] Searched documentation and issues

[REQUIRED] Question

I am trying to calculate the live latency of a live stream. I was not able to find any API to get the value from so I tried to implement the solution suggested in #6099.

long currentSystemTime = System.currentTimeMillis(); Timeline.Window window = player.getCurrentTimeline().getWindow(player.getCurrentWindowIndex(), new Timeline.Window()); long liveLatency = currentSystemTime - (player.getCurrentTimeline().getWindow(player.getCurrentWindowIndex(),window).windowStartTimeMs + player.getCurrentPosition());

the problem is that currentSystemTime is not synchronized with the server time. Is there any API to request the server UTC Time after it has been resolved in onTimestampResolved?

The latest dev-v2 branch has a method player.getCurrentLiveOffset() that returns the live offset. However, for HLS, it does not adjust the offset for out-of-sync client clocks. We may add this feature as part of #5011, but it's not strictly needed for HLS live playback because the playback itself is not dependent on the client clock (that is different from DASH for example, where the client clock may be relevant).

However, you can retrieve and add the offset yourself by using SntpClient.initialize(loader, callback) to load the offset and then calculate SystemClock.elapsedRealtime() + SntpClient.getElapsedRealtimeOffsetMs() - window.windowStartTimeMs + player.getCurrentPosition().

Closing under the assumption that the question was answered.