Skip to content

Commit 8bd337b

Browse files
committed
Fix review comments
1 parent 92e2a0b commit 8bd337b

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

libraries/common/src/main/java/androidx/media3/common/util/Util.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,21 @@ public static byte[] getBytesFromHexString(String hexString) {
22332233
*/
22342234
@UnstableApi
22352235
public static String toHexString(byte[] bytes) {
2236-
return BaseEncoding.base16().lowerCase().encode(bytes);
2236+
return toHexString(bytes, 0, bytes.length);
2237+
}
2238+
2239+
/**
2240+
* Returns a string containing a lower-case hex representation of the bytes provided.
2241+
*
2242+
* @param bytes The byte data to convert to hex.
2243+
* @param offset The offset into data to read from.
2244+
* @param length The number of bytes to read from data.
2245+
* @return A String containing the hex representation of {@code bytes} (considering {@code offset}
2246+
* and {@code length}).
2247+
*/
2248+
@UnstableApi
2249+
public static String toHexString(byte[] bytes, int offset, int length) {
2250+
return BaseEncoding.base16().lowerCase().encode(bytes, offset, length);
22372251
}
22382252

22392253
@UnstableApi

libraries/common/src/test/java/androidx/media3/common/util/UtilTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,13 @@ public void toHexString_returnsHexString() {
10661066
assertThat(Util.toHexString(bytes)).isEqualTo("12fc06");
10671067
}
10681068

1069+
@Test
1070+
public void toHexString_withOffsetAndLength_returnsHexString() {
1071+
byte[] bytes = createByteArray(0x12, 0xFC, 0x06, 0x2B);
1072+
1073+
assertThat(Util.toHexString(bytes, /* offset= */ 1, /* length= */ 2)).isEqualTo("fc06");
1074+
}
1075+
10691076
@Test
10701077
public void getCodecsOfType_withNull_returnsNull() {
10711078
assertThat(getCodecsOfType(null, C.TRACK_TYPE_VIDEO)).isNull();

libraries/extractor/src/main/java/androidx/media3/extractor/mp3/XingFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static XingFrame parse(MpegAudioUtil.Header mpegAudioHeader, ParsableByte
147147
public long computeDurationUs() {
148148
if (frameCount == C.LENGTH_UNSET || frameCount == 0) {
149149
// If the frame count is missing/invalid, the header can't be used to determine the duration.
150-
return C.LENGTH_UNSET;
150+
return C.TIME_UNSET;
151151
}
152152
long sampleCount = frameCount * header.samplesPerFrame;
153153
if (encoderDelay != C.LENGTH_UNSET && encoderPadding != C.LENGTH_UNSET) {

libraries/extractor/src/test/java/androidx/media3/extractor/mp3/Mp3ExtractorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ private static int findMpegFramePositionBeforeTag(ByteBuffer data, int tagOffset
469469
return framePosition;
470470
}
471471
}
472-
throw new IllegalArgumentException("No tag found in " + Util.toHexString(data.array()));
472+
throw new IllegalArgumentException(
473+
"No tag found in " + Util.toHexString(data.array(), data.arrayOffset(), data.limit()));
473474
}
474475
}

0 commit comments

Comments
 (0)