Improve retrieveTrackFormat() java doc and remove catch block

PiperOrigin-RevId: 608939192
This commit is contained in:
sheenachhabra 2024-02-21 04:07:33 -08:00 committed by Copybara-Service
parent 7a632a43ba
commit a82d7e7098
2 changed files with 20 additions and 14 deletions

View file

@ -362,21 +362,25 @@ public class TestUtil {
return Uri.parse("asset:///" + assetPath);
}
/** Returns the {@linkplain Format track format} from the media file. */
/**
* Returns the {@link Format} for a given {@link C.TrackType} from a media file.
*
* <p>If more than one track is present for the given {@link C.TrackType} then only one track's
* {@link Format} is returned.
*
* @param context The {@link Context};
* @param filePath The media file path.
* @param trackType The {@link C.TrackType}.
* @return The {@link Format} for the given {@link C.TrackType}.
* @throws ExecutionException If an error occurred while retrieving file's metadata.
* @throws InterruptedException If interrupted while retrieving file's metadata.
*/
public static Format retrieveTrackFormat(
Context context, String filePath, @C.TrackType int trackType) {
Context context, String filePath, @C.TrackType int trackType)
throws ExecutionException, InterruptedException {
TrackGroupArray trackGroupArray;
try {
trackGroupArray =
MetadataRetriever.retrieveMetadata(context, MediaItem.fromUri("file://" + filePath))
.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
trackGroupArray =
MetadataRetriever.retrieveMetadata(context, MediaItem.fromUri("file://" + filePath)).get();
for (int i = 0; i < trackGroupArray.length; i++) {
TrackGroup trackGroup = trackGroupArray.get(i);
if (trackGroup.type == trackType) {

View file

@ -39,6 +39,7 @@ import androidx.media3.test.utils.FakeExtractorOutput;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.base.Predicate;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -272,7 +273,8 @@ public class TransformerWithInAppMuxerEndToEndTest {
*/
@Nullable
private static Metadata.Entry retrieveMetadata(
Context context, @Nullable String filePath, Predicate<Metadata.Entry> predicate) {
Context context, @Nullable String filePath, Predicate<Metadata.Entry> predicate)
throws ExecutionException, InterruptedException {
Format videoTrackFormat = retrieveTrackFormat(context, filePath, C.TRACK_TYPE_VIDEO);
@Nullable
Metadata.Entry metadataEntryFromVideoTrack = findMetadataEntry(videoTrackFormat, predicate);