Skip to content

Commit

Permalink
Add JavaDoc to some undocumented methods and move them
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 527870443
(cherry picked from commit 336d4b3)
  • Loading branch information
marcbaechinger authored and icbaker committed May 15, 2023
1 parent 40ef64a commit 179e35b
Showing 1 changed file with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1411,13 +1411,7 @@ public static Pair<PlayerInfo, BundlingExclusions> mergePlayerInfo(
return new Pair<>(mergedPlayerInfo, mergedBundlingExclusions);
}

private static byte[] convertToByteArray(Bitmap bitmap) throws IOException {
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
bitmap.compress(Bitmap.CompressFormat.PNG, /* ignored */ 0, stream);
return stream.toByteArray();
}
}

/** Generates an array of {@code n} indices. */
public static int[] generateUnshuffledIndices(int n) {
int[] indices = new int[n];
for (int i = 0; i < n; i++) {
Expand All @@ -1426,6 +1420,10 @@ public static int[] generateUnshuffledIndices(int n) {
return indices;
}

/**
* Calculates the buffered percentage of the given buffered position and the duration in
* milliseconds.
*/
public static int calculateBufferedPercentage(long bufferedPositionMs, long durationMs) {
return bufferedPositionMs == C.TIME_UNSET || durationMs == C.TIME_UNSET
? 0
Expand All @@ -1434,26 +1432,38 @@ public static int calculateBufferedPercentage(long bufferedPositionMs, long dura
: Util.constrainValue((int) ((bufferedPositionMs * 100) / durationMs), 0, 100);
}

/**
* Sets media items with start index and position for the given {@link Player} by honoring the
* available commands.
*
* @param player The player to set the media items.
* @param mediaItemsWithStartPosition The media items, the index and the position to set.
*/
public static void setMediaItemsWithStartIndexAndPosition(
PlayerWrapper player, MediaSession.MediaItemsWithStartPosition mediaItemsWithStartPosition) {
Player player, MediaSession.MediaItemsWithStartPosition mediaItemsWithStartPosition) {
if (mediaItemsWithStartPosition.startIndex == C.INDEX_UNSET) {
if (player.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)) {
player.setMediaItems(mediaItemsWithStartPosition.mediaItems, /* resetPosition= */ true);
} else if (!mediaItemsWithStartPosition.mediaItems.isEmpty()) {
player.setMediaItem(
mediaItemsWithStartPosition.mediaItems.get(0), /* resetPosition= */ true);
}
} else {
if (player.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)) {
player.setMediaItems(
mediaItemsWithStartPosition.mediaItems,
mediaItemsWithStartPosition.startIndex,
mediaItemsWithStartPosition.startPositionMs);
} else if (!mediaItemsWithStartPosition.mediaItems.isEmpty()) {
player.setMediaItem(
mediaItemsWithStartPosition.mediaItems.get(0),
mediaItemsWithStartPosition.startPositionMs);
}
} else if (player.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)) {
player.setMediaItems(
mediaItemsWithStartPosition.mediaItems,
mediaItemsWithStartPosition.startIndex,
mediaItemsWithStartPosition.startPositionMs);
} else if (!mediaItemsWithStartPosition.mediaItems.isEmpty()) {
player.setMediaItem(
mediaItemsWithStartPosition.mediaItems.get(0),
mediaItemsWithStartPosition.startPositionMs);
}
}

private static byte[] convertToByteArray(Bitmap bitmap) throws IOException {
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
bitmap.compress(Bitmap.CompressFormat.PNG, /* ignored */ 0, stream);
return stream.toByteArray();
}
}

Expand Down

0 comments on commit 179e35b

Please sign in to comment.