mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Format negative durations correctly
formatDuration() previously emitted strings like '00:-49' for negative values because the modulo operations propagated the sign. This shows up on live streams that briefly report a negative position during reload, and as the basis for a planned 'behind live edge' indicator. Recurse on the absolute value when negative so we get a clean -MM:SS (or -HH:MM:SS) format.
This commit is contained in:
@@ -251,6 +251,11 @@ fun String.fixHtmlWhitespace(): Spanned {
|
||||
}
|
||||
|
||||
fun Long.formatDuration(): String {
|
||||
// Negative durations show up for live streams seeked behind the seek-window start, or
|
||||
// briefly while the player is reseating. Recurse on the absolute value so we get a clean
|
||||
// `-MM:SS` instead of garbage like `00:-49`.
|
||||
if (this < 0) return "-" + (-this).formatDuration()
|
||||
|
||||
val hours = this / 3600000
|
||||
val minutes = (this % 3600000) / 60000
|
||||
val seconds = (this % 60000) / 1000
|
||||
|
||||
Reference in New Issue
Block a user