mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Util.getStringForTime() prefixes negative times
Fix bug to place the negative sign in the beginning of the returned String. PiperOrigin-RevId: 333504868
This commit is contained in:
parent
3b14b05d93
commit
cf30ee504e
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.util;
|
||||
|
||||
import static android.content.Context.UI_MODE_SERVICE;
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
@ -1847,13 +1848,16 @@ public final class Util {
|
||||
if (timeMs == C.TIME_UNSET) {
|
||||
timeMs = 0;
|
||||
}
|
||||
String prefix = timeMs < 0 ? "-" : "";
|
||||
timeMs = abs(timeMs);
|
||||
long totalSeconds = (timeMs + 500) / 1000;
|
||||
long seconds = totalSeconds % 60;
|
||||
long minutes = (totalSeconds / 60) % 60;
|
||||
long hours = totalSeconds / 3600;
|
||||
builder.setLength(0);
|
||||
return hours > 0 ? formatter.format("%d:%02d:%02d", hours, minutes, seconds).toString()
|
||||
: formatter.format("%02d:%02d", minutes, seconds).toString();
|
||||
return hours > 0
|
||||
? formatter.format("%s%d:%02d:%02d", prefix, hours, minutes, seconds).toString()
|
||||
: formatter.format("%s%02d:%02d", prefix, minutes, seconds).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.util.Util.binarySearchCeil;
|
||||
import static com.google.android.exoplayer2.util.Util.binarySearchFloor;
|
||||
import static com.google.android.exoplayer2.util.Util.escapeFileName;
|
||||
import static com.google.android.exoplayer2.util.Util.getCodecsOfType;
|
||||
import static com.google.android.exoplayer2.util.Util.getStringForTime;
|
||||
import static com.google.android.exoplayer2.util.Util.parseXsDateTime;
|
||||
import static com.google.android.exoplayer2.util.Util.parseXsDuration;
|
||||
import static com.google.android.exoplayer2.util.Util.unescapeFileName;
|
||||
@ -37,6 +38,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Formatter;
|
||||
import java.util.Random;
|
||||
import java.util.zip.Deflater;
|
||||
import org.junit.Test;
|
||||
@ -1082,6 +1084,12 @@ public class UtilTest {
|
||||
assertThat(Util.tableExists(database, "table")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStringForTime_withNegativeTime_setsNegativePrefix() {
|
||||
assertThat(getStringForTime(new StringBuilder(), new Formatter(), /* timeMs= */ -35000))
|
||||
.isEqualTo("-00:35");
|
||||
}
|
||||
|
||||
private static void assertEscapeUnescapeFileName(String fileName, String escapedFileName) {
|
||||
assertThat(escapeFileName(fileName)).isEqualTo(escapedFileName);
|
||||
assertThat(unescapeFileName(escapedFileName)).isEqualTo(fileName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user