# TestUtil

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/TestUtil.java+class:androidx.media3.test.utils.TestUtil)

*** ** * ** ***


```
@UnstableApi
public class TestUtil
```

<br />

*** ** * ** ***

Utility methods for tests.

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#PSNR_THRESHOLD() = 35.0f` Luma PSNR values between 30 and 50 are considered good for lossy compression (See [Quality estimation with PSNR](https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Quality_estimation_with_PSNR) ). |

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertBitmapsAreSimilar(android.graphics.Bitmap,android.graphics.Bitmap,double)( https://developer.android.com/reference/android/graphics/Bitmap.html expectedBitmap, https://developer.android.com/reference/android/graphics/Bitmap.html actualBitmap, double psnrThresholdDb )` Asserts whether actual bitmap is very similar to the expected bitmap at some quality level. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertBufferInfosEqual(android.media.MediaCodec.BufferInfo,android.media.MediaCodec.BufferInfo)( https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html expected, https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html actual )` Returns whether two `https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html` are equal. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertDataSourceContent(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,byte[],boolean)( https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength )` Asserts that data read from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` matches `expected`. |
| `static void` | `<T extends https://developer.android.com/reference/java/lang/Object.html, F extends T> https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertForwardingClassForwardsAllMethods(java.lang.Class<T>,com.google.common.base.Function<T,F>)( https://developer.android.com/reference/java/lang/Class.html<T> superType, https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Function.html<T, F> forwardingInstanceFactory )` Use reflection to assert that calling every non-final method declared on `superType` on an instance of `forwardingType` results in the call being forwarded to the ` superType` delegate. |
| `static void` | `<T extends https://developer.android.com/reference/java/lang/Object.html, F extends T> https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertForwardingClassForwardsAllMethodsExcept(java.lang.Class<T>,com.google.common.base.Function<T,F>,java.util.Set<java.lang.String>)( https://developer.android.com/reference/java/lang/Class.html<T> superType, https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Function.html<T, F> forwardingInstanceFactory, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html> excludedMethods )` Use reflection to assert that calling every non-final, non-excluded method declared on ` superType` on an instance of `forwardingType` results in the call being forwarded to the `superType` delegate. |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertFp16BitmapsAreSimilar(android.graphics.Bitmap,android.graphics.Bitmap,double)( https://developer.android.com/reference/android/graphics/Bitmap.html expectedBitmap, https://developer.android.com/reference/android/graphics/Bitmap.html actualBitmap, double psnrThresholdDb )` Asserts whether actual FP16 bitmap is very similar to the expected FP16 bitmap at some quality level. |
| `static void` | `<T> https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertSubclassOverridesAllMethods(java.lang.Class<T>,java.lang.Class<? extends T>)( https://developer.android.com/reference/java/lang/Class.html<T> superType, https://developer.android.com/reference/java/lang/Class.html<T> subType )` Use reflection to assert that every non-final method declared on `superType` is overridden by `subType`. |
| `static void` | `<T> https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertSubclassOverridesAllMethodsExcept(java.lang.Class<T>,java.lang.Class<? extends T>,java.util.Set<java.lang.String>)( https://developer.android.com/reference/java/lang/Class.html<T> superType, https://developer.android.com/reference/java/lang/Class.html<T> subType, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html> excludedMethods )` Use reflection to assert that every non-final, non-excluded method declared on ` superType` is overridden by `subType`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#assertTimelinesSame(java.util.List<androidx.media3.common.Timeline>,java.util.List<androidx.media3.common.Timeline>)( https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Timeline> actualTimelines, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Timeline> expectedTimelines )` Asserts that the actual timelines are the same to the expected timelines. |
| `static https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildAssetUri(java.lang.String)(https://developer.android.com/reference/java/lang/String.html assetPath)` Returns the `https://developer.android.com/reference/android/net/Uri.html` for the given asset path. |
| `static double[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildDoubleTestSamples(int,java.util.Random)(int length, https://developer.android.com/reference/java/util/Random.html random)` Returns an array of random doubles between `[-1; 1]` with the specified length. |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildFloatTestSamples(int,java.util.Random)(int length, https://developer.android.com/reference/java/util/Random.html random)` Returns an array of random floats between `[-1; 1]` with the specified length. |
| `static https://developer.android.com/reference/androidx/media3/common/MediaItem` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildFullyCustomizedMediaItem()()` Returns a `https://developer.android.com/reference/androidx/media3/common/MediaItem` that has all fields set to non-default values. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildTestData(int)(int length)` Equivalent to `buildTestData(length, length)`. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildTestData(int,java.util.Random)(int length, https://developer.android.com/reference/java/util/Random.html random)` Generates an array of random bytes with the specified length. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildTestData(int,int)(int length, int seed)` Generates an array of random bytes with the specified length. |
| `static https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#buildTestString(int,java.util.Random)(int length, https://developer.android.com/reference/java/util/Random.html random)` Generates a random string with the specified length. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteArray(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer)` Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `byte[]`. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteArray(int...)(int[] bytes)` Converts an array of integers in the range \[0, 255\] into an equivalent byte array. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(float[])(float[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(double[])(double[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(int[])(int[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(long[])(long[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(short[])(short[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteBuffer(byte[])(byte[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`. |
| `static https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteCountingAudioProcessor(java.util.concurrent.atomic.AtomicInteger)(https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger.html byteCount)` Returns an `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` that counts the number of bytes input to it. |
| `static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Byte.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createByteList(int...)(int[] bytes)` Converts an array of integers in the range \[0, 255\] into an equivalent byte list. |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createFloatArray(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer)` Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `float[]`. |
| `static int[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createInt24Array(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer)` Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as 24-bit integer values in `int[]`. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createInt24ByteBuffer(int[])(int[] data)` Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` with the contents of `data` as 24-bit integers. |
| `static int[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createIntArray(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer)` Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `int[]`. |
| `static https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createInternalCacheFile(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileName)` Creates a `https://developer.android.com/reference/java/io/File.html``fileName` within the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`. |
| `static https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createInternalCacheFile(android.content.Context,java.lang.String,java.lang.String)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html directoryName, https://developer.android.com/reference/java/lang/String.html fileName )` Creates a `https://developer.android.com/reference/java/io/File.html``fileName` in a directory `directoryName` within the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`. |
| `static https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataInputBuffer` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createMetadataInputBuffer(byte[])(byte[] data)` Create a new `https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataInputBuffer` and copy `data` into the backing `https://developer.android.com/reference/java/nio/ByteBuffer.html`. |
| `static short[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createShortArray(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html byteBuffer)` Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `short[]`. |
| `static https://developer.android.com/reference/android/view/SurfaceView.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createSurfaceView(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` Creates a `https://developer.android.com/reference/android/view/SurfaceView.html` for tests where the creation is moved to the main thread if run on a non-Looper thread. |
| `static https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createTestFile(java.io.File,java.lang.String)(https://developer.android.com/reference/java/io/File.html directory, https://developer.android.com/reference/java/lang/String.html name)` Writes one byte long test data to the file and returns it. |
| `static https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createTestFile(java.io.File,long)(https://developer.android.com/reference/java/io/File.html file, long length)` Writes test data with the specified length to the file and returns it. |
| `static https://developer.android.com/reference/java/io/File.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#createTestFile(java.io.File,java.lang.String,long)(https://developer.android.com/reference/java/io/File.html directory, https://developer.android.com/reference/java/lang/String.html name, long length)` Writes test data with the specified length to the file and returns it. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#extractAllSamplesFromByteArray(androidx.media3.extractor.Extractor,byte[])(https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor, byte[] data)` Extracts all samples from the given byte array into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#extractAllSamplesFromFile(androidx.media3.extractor.Extractor,android.content.Context,java.lang.String)( https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor, https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileName )` Extracts all samples from the given file into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#extractAllSamplesFromFilePath(androidx.media3.extractor.Extractor,java.lang.String)(https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor, https://developer.android.com/reference/java/lang/String.html filePath)` Extracts all samples from the given file into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`. |
| `static https://developer.android.com/reference/androidx/media3/extractor/SeekMap` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#extractSeekMap(androidx.media3.extractor.Extractor,androidx.media3.test.utils.FakeExtractorOutput,androidx.media3.datasource.DataSource,android.net.Uri)( https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor, https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput output, https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/android/net/Uri.html uri )` Reads from the given input using the given `https://developer.android.com/reference/androidx/media3/extractor/Extractor`, until it can produce the `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` and all of the track formats have been identified, or until the extractor encounters EOF. |
| `static float` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#generateFloatInRange(java.util.Random,com.google.common.collect.Range<java.lang.Float>)(https://developer.android.com/reference/java/util/Random.html random, https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/Range.html<https://developer.android.com/reference/java/lang/Float.html> range)` Returns a randomly generated float within the specified range, using `random` as random number generator. |
| `static long` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#generateLong(java.util.Random,long,long)(https://developer.android.com/reference/java/util/Random.html random, long origin, long bound)` Returns a long between `origin` (inclusive) and `bound` (exclusive), given ` random`. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getByteArray(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileName)` Returns the bytes of an asset file. |
| `static byte[]` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getByteArrayFromFilePath(java.lang.String)(https://developer.android.com/reference/java/lang/String.html filePath)` Returns the bytes of a file using its file path. |
| `static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<@https://developer.android.com/reference/androidx/media3/common/Player.Command https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getCommandsAsList(androidx.media3.common.Player.Commands)(https://developer.android.com/reference/androidx/media3/common/Player.Commands commands)` Returns an `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` with the `https://developer.android.com/reference/androidx/media3/common/Player.Command` contained in `commands`. |
| `static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<@https://developer.android.com/reference/androidx/media3/common/Player.Event https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getEventsAsList(androidx.media3.common.Player.Events)(https://developer.android.com/reference/androidx/media3/common/Player.Events events)` Returns an `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` with the `https://developer.android.com/reference/androidx/media3/common/Player.Event` contained in ` events`. |
| `static https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getExtractorInputFromPosition(androidx.media3.datasource.DataSource,long,android.net.Uri)( https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, long position, https://developer.android.com/reference/android/net/Uri.html uri )` Returns an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` to read from the given input at given position. |
| `static https://developer.android.com/reference/androidx/media3/database/DatabaseProvider` | `[getInMemoryDatabaseProvider](https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getInMemoryDatabaseProvider())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/test/utils/InMemoryDatabaseRule`. <br /> |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getInnerClass(java.lang.Class<?>,java.lang.String)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, https://developer.android.com/reference/java/lang/String.html className)` Returns an inner class of `clazz` called `className` if it exists, otherwise null. |
| `static https://developer.android.com/reference/java/io/InputStream.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getInputStream(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileName)` Returns an `https://developer.android.com/reference/java/io/InputStream.html` for reading from an asset file. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getNonRandomByteBuffer(int,int)(int frameCount, int bytesPerFrame)` Returns a non-random `https://developer.android.com/reference/java/nio/ByteBuffer.html` filled with `frameCount * bytesPerFrame` bytes. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getPeriodicSamplesBuffer(int,int)(int sampleCount, int period)` Returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` filled with alternating 16-bit PCM samples as per the provided period length. |
| `static https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/reflect/Method.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getPublicMethods(java.lang.Class<?>)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz)` Returns all the public methods of a Java class (except those defined by `https://developer.android.com/reference/java/lang/Object.html`). |
| `static https://developer.android.com/reference/java/lang/Iterable.html<https://developer.android.com/reference/java/lang/reflect/Method.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getPublicOverridableMethods(java.lang.Class<?>)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz)` Returns all the public overridable methods of a Java class (except those defined by `https://developer.android.com/reference/java/lang/Object.html`). |
| `static https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getString(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileName)` Returns a `https://developer.android.com/reference/java/lang/String.html` read from an asset file. |
| `static https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getThrowingBundle()()` Returns a `https://developer.android.com/reference/android/os/Bundle.html` that will throw an exception at the first attempt to read a value. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#repeatFlakyTest(int,org.junit.function.ThrowingRunnable)(int maxRepetitions, https://junit.org/junit4/javadoc/latest/org/junit/function/ThrowingRunnable.html testImpl)` Repeats the potentially flaky test multiple times if needed. |
| `static https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#retrieveTrackFormat(android.content.Context,java.lang.String,int)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html fileUri, @https://developer.android.com/reference/androidx/media3/common/C.TrackType int trackType )` Returns the `https://developer.android.com/reference/androidx/media3/common/Format` for a given `https://developer.android.com/reference/androidx/media3/common/C.TrackType` from a media file. |
| `static int` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#seekToTimeUs(androidx.media3.extractor.Extractor,androidx.media3.extractor.SeekMap,long,androidx.media3.datasource.DataSource,androidx.media3.test.utils.FakeTrackOutput,android.net.Uri)( https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor, https://developer.android.com/reference/androidx/media3/extractor/SeekMap seekMap, long seekTimeUs, https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput trackOutput, https://developer.android.com/reference/android/net/Uri.html uri )` Seeks to the given seek time of the stream from the given input, and keeps reading from the input until we can extract at least one sample following the seek position, or until end-of-input is reached. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#timelinesAreSame(androidx.media3.common.Timeline,androidx.media3.common.Timeline)(https://developer.android.com/reference/androidx/media3/common/Timeline thisTimeline, https://developer.android.com/reference/androidx/media3/common/Timeline thatTimeline)` Returns true if `thisTimeline` is equal to `thatTimeline`, ignoring `https://developer.android.com/reference/androidx/media3/common/Timeline.Window#uid()` and `https://developer.android.com/reference/androidx/media3/common/Timeline.Period#uid()` values, and shuffle order. |

## Constants

### PSNR_THRESHOLD

```
public static final float PSNR_THRESHOLD = 35.0f
```

Luma PSNR values between 30 and 50 are considered good for lossy compression (See [Quality estimation with PSNR](https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Quality_estimation_with_PSNR) ).

## Public methods

### assertBitmapsAreSimilar

```
public static void assertBitmapsAreSimilar(
    Bitmap expectedBitmap,
    Bitmap actualBitmap,
    double psnrThresholdDb
)
```

Asserts whether actual bitmap is very similar to the expected bitmap at some quality level.

This is defined as their PSNR value is greater than or equal to the threshold. The higher the threshold, the more similar they are.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html expectedBitmap` | The expected bitmap. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html actualBitmap` | The actual bitmap. |
| `double psnrThresholdDb` | The PSNR threshold (in dB), at or above which bitmaps are considered very similar. |

### assertBufferInfosEqual

```
public static void assertBufferInfosEqual(
    MediaCodec.BufferInfo expected,
    MediaCodec.BufferInfo actual
)
```

Returns whether two `https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html` are equal.

### assertDataSourceContent

```
public static void assertDataSourceContent(
    DataSource dataSource,
    DataSpec dataSpec,
    byte[] expectedData,
    boolean expectKnownLength
)
```

Asserts that data read from a `https://developer.android.com/reference/androidx/media3/datasource/DataSource` matches `expected`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSource` through which to read. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSpec` to use when opening the `https://developer.android.com/reference/androidx/media3/datasource/DataSource`. |
| `byte[] expectedData` | The expected data. |
| `boolean expectKnownLength` | Whether to assert that `https://developer.android.com/reference/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` returns the expected data length. If false then it's asserted that `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` is returned. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading fom the `https://developer.android.com/reference/androidx/media3/datasource/DataSource`. |

### assertForwardingClassForwardsAllMethods

```
public static void <T extends Object, F extends T> assertForwardingClassForwardsAllMethods(
    Class<T> superType,
    Function<T, F> forwardingInstanceFactory
)
```

Use reflection to assert that calling every non-final method declared on `superType` on an instance of `forwardingType` results in the call being forwarded to the `
superType` delegate.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/reflect/InvocationTargetException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |

### assertForwardingClassForwardsAllMethodsExcept

```
public static void <T extends Object, F extends T> assertForwardingClassForwardsAllMethodsExcept(
    Class<T> superType,
    Function<T, F> forwardingInstanceFactory,
    Set<String> excludedMethods
)
```

Use reflection to assert that calling every non-final, non-excluded method declared on `
superType` on an instance of `forwardingType` results in the call being forwarded to the `superType` delegate.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/reflect/InvocationTargetException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |

### assertFp16BitmapsAreSimilar

```
@RequiresApi(value = 29)
public static void assertFp16BitmapsAreSimilar(
    Bitmap expectedBitmap,
    Bitmap actualBitmap,
    double psnrThresholdDb
)
```

Asserts whether actual FP16 bitmap is very similar to the expected FP16 bitmap at some quality level.

This is defined as their PSNR value is greater than or equal to the threshold. The higher the threshold, the more similar they are.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html expectedBitmap` | The expected FP16 bitmap. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html actualBitmap` | The actual FP16 bitmap. |
| `double psnrThresholdDb` | The PSNR threshold (in dB), at or above which bitmaps are considered very similar. |

### assertSubclassOverridesAllMethods

```
public static void <T> assertSubclassOverridesAllMethods(
    Class<T> superType,
    Class<T> subType
)
```

Use reflection to assert that every non-final method declared on `superType` is overridden by `subType`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NoSuchMethodException.html` |   |

### assertSubclassOverridesAllMethodsExcept

```
public static void <T> assertSubclassOverridesAllMethodsExcept(
    Class<T> superType,
    Class<T> subType,
    Set<String> excludedMethods
)
```

Use reflection to assert that every non-final, non-excluded method declared on `
superType` is overridden by `subType`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NoSuchMethodException.html` |   |

### assertTimelinesSame

```
public static void assertTimelinesSame(
    List<Timeline> actualTimelines,
    List<Timeline> expectedTimelines
)
```

Asserts that the actual timelines are the same to the expected timelines. This assert differs from testing equality by not comparing:

- Period IDs, which may be different due to ID mapping of child source period IDs.
- Shuffle order, which by default is random and non-deterministic.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Timeline> actualTimelines` | A list of actual `https://developer.android.com/reference/androidx/media3/common/Timeline`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/common/Timeline> expectedTimelines` | A list of expected `https://developer.android.com/reference/androidx/media3/common/Timeline`. |

### buildAssetUri

```
public static Uri buildAssetUri(String assetPath)
```

Returns the `https://developer.android.com/reference/android/net/Uri.html` for the given asset path.

### buildDoubleTestSamples

```
public static double[] buildDoubleTestSamples(int length, Random random)
```

Returns an array of random doubles between `[-1; 1]` with the specified length.

### buildFloatTestSamples

```
public static float[] buildFloatTestSamples(int length, Random random)
```

Returns an array of random floats between `[-1; 1]` with the specified length.

### buildFullyCustomizedMediaItem

```
public static MediaItem buildFullyCustomizedMediaItem()
```

Returns a `https://developer.android.com/reference/androidx/media3/common/MediaItem` that has all fields set to non-default values.

### buildTestData

```
public static byte[] buildTestData(int length)
```

Equivalent to `buildTestData(length, length)`.

| Parameters |
|---|---|
| `int length` | The length of the array. |

| Returns |
|---|---|
| `byte[]` | The generated array. |

### buildTestData

```
public static byte[] buildTestData(int length, Random random)
```

Generates an array of random bytes with the specified length.

| Parameters |
|---|---|
| `int length` | The length of the array. |
| `https://developer.android.com/reference/java/util/Random.html random` | A source of randomness. |

| Returns |
|---|---|
| `byte[]` | The generated array. |

### buildTestData

```
public static byte[] buildTestData(int length, int seed)
```

Generates an array of random bytes with the specified length.

| Parameters |
|---|---|
| `int length` | The length of the array. |
| `int seed` | A seed for an internally created `https://developer.android.com/reference/java/util/Random.html`. |

| Returns |
|---|---|
| `byte[]` | The generated array. |

### buildTestString

```
public static String buildTestString(int length, Random random)
```

Generates a random string with the specified length.

| Parameters |
|---|---|
| `int length` | The length of the string. |
| `https://developer.android.com/reference/java/util/Random.html random` | A source of randomness. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The generated string. |

### createByteArray

```
public static byte[] createByteArray(ByteBuffer byteBuffer)
```

Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `byte[]`.

### createByteArray

```
public static byte[] createByteArray(int[] bytes)
```

Converts an array of integers in the range \[0, 255\] into an equivalent byte array.

| Parameters |
|---|---|
| `int[] bytes` | An array of integers, all of which must be in the range \[0, 255\]. |

| Returns |
|---|---|
| `byte[]` | The equivalent byte array. |

### createByteBuffer

```
public static ByteBuffer createByteBuffer(float[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteBuffer

```
public static ByteBuffer createByteBuffer(double[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteBuffer

```
public static ByteBuffer createByteBuffer(int[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteBuffer

```
public static ByteBuffer createByteBuffer(long[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteBuffer

```
public static ByteBuffer createByteBuffer(short[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteBuffer

```
public static ByteBuffer createByteBuffer(byte[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the `data`.

### createByteCountingAudioProcessor

```
public static AudioProcessor createByteCountingAudioProcessor(AtomicInteger byteCount)
```

Returns an `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor` that counts the number of bytes input to it.

### createByteList

```
public static ImmutableList<Byte> createByteList(int[] bytes)
```

Converts an array of integers in the range \[0, 255\] into an equivalent byte list.

| Parameters |
|---|---|
| `int[] bytes` | An array of integers, all of which must be in the range \[0, 255\]. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Byte.html>` | The equivalent byte list. |

### createFloatArray

```
public static float[] createFloatArray(ByteBuffer byteBuffer)
```

Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `float[]`.

### createInt24Array

```
public static int[] createInt24Array(ByteBuffer byteBuffer)
```

Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as 24-bit integer values in `int[]`.

### createInt24ByteBuffer

```
public static ByteBuffer createInt24ByteBuffer(int[] data)
```

Creates a `https://developer.android.com/reference/java/nio/ByteBuffer.html` with the contents of `data` as 24-bit integers.

### createIntArray

```
public static int[] createIntArray(ByteBuffer byteBuffer)
```

Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `int[]`.

### createInternalCacheFile

```
public static File createInternalCacheFile(Context context, String fileName)
```

Creates a `https://developer.android.com/reference/java/io/File.html``fileName` within the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`.

If a file of that name already exists, it is overwritten.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/java/lang/String.html fileName` | The filename to save to the cache. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### createInternalCacheFile

```
public static File createInternalCacheFile(
    Context context,
    String directoryName,
    String fileName
)
```

Creates a `https://developer.android.com/reference/java/io/File.html``fileName` in a directory `directoryName` within the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`.

If a file of that name already exists, it is overwritten.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/java/lang/String.html directoryName` | The directory name within the internal cache to save the file in. |
| `https://developer.android.com/reference/java/lang/String.html fileName` | The filename to save to the cache. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### createMetadataInputBuffer

```
public static MetadataInputBuffer createMetadataInputBuffer(byte[] data)
```

Create a new `https://developer.android.com/reference/androidx/media3/extractor/metadata/MetadataInputBuffer` and copy `data` into the backing `https://developer.android.com/reference/java/nio/ByteBuffer.html`.

### createShortArray

```
public static short[] createShortArray(ByteBuffer byteBuffer)
```

Gets the underlying data of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` as a `short[]`.

### createSurfaceView

```
public static SurfaceView createSurfaceView(Context context)
```

Creates a `https://developer.android.com/reference/android/view/SurfaceView.html` for tests where the creation is moved to the main thread if run on a non-Looper thread. This is needed on API \<26 where `https://developer.android.com/reference/android/view/SurfaceView.html` cannot be created on a non-Looper thread.

### createTestFile

```
public static File createTestFile(File directory, String name)
```

Writes one byte long test data to the file and returns it.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### createTestFile

```
public static File createTestFile(File file, long length)
```

Writes test data with the specified length to the file and returns it.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### createTestFile

```
public static File createTestFile(File directory, String name, long length)
```

Writes test data with the specified length to the file and returns it.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### extractAllSamplesFromByteArray

```
public static FakeExtractorOutput extractAllSamplesFromByteArray(Extractor extractor, byte[] data)
```

Extracts all samples from the given byte array into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor` | The `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to be used. |
| `byte[] data` | The byte array data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | The `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` containing the extracted samples. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any `https://developer.android.com/reference/androidx/media3/extractor/SeekMap`. |

### extractAllSamplesFromFile

```
public static FakeExtractorOutput extractAllSamplesFromFile(
    Extractor extractor,
    Context context,
    String fileName
)
```

Extracts all samples from the given file into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor` | The `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to be used. |
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/java/lang/String.html fileName` | The name of the input file. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | The `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` containing the extracted samples. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any `https://developer.android.com/reference/androidx/media3/extractor/SeekMap`. |

### extractAllSamplesFromFilePath

```
public static FakeExtractorOutput extractAllSamplesFromFilePath(Extractor extractor, String filePath)
```

Extracts all samples from the given file into a `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor` | The `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to be used. |
| `https://developer.android.com/reference/java/lang/String.html filePath` | The file path. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput` | The `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` containing the extracted samples. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any `https://developer.android.com/reference/androidx/media3/extractor/SeekMap`. |

### extractSeekMap

```
public static SeekMap extractSeekMap(
    Extractor extractor,
    FakeExtractorOutput output,
    DataSource dataSource,
    Uri uri
)
```

Reads from the given input using the given `https://developer.android.com/reference/androidx/media3/extractor/Extractor`, until it can produce the `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` and all of the track formats have been identified, or until the extractor encounters EOF.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor` | The `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to extractor from input. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeExtractorOutput output` | The `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` to store the extracted `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` and track. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSource` that will be used to read from the input. |
| `https://developer.android.com/reference/android/net/Uri.html uri` | The Uri of the input. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` | The extracted `https://developer.android.com/reference/androidx/media3/extractor/SeekMap`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any `https://developer.android.com/reference/androidx/media3/extractor/SeekMap`. |

### generateFloatInRange

```
public static float generateFloatInRange(Random random, Range<Float> range)
```

Returns a randomly generated float within the specified range, using `random` as random number generator.

`range` must be a bounded range.

### generateLong

```
public static long generateLong(Random random, long origin, long bound)
```

Returns a long between `origin` (inclusive) and `bound` (exclusive), given `
random`.

### getByteArray

```
public static byte[] getByteArray(Context context, String fileName)
```

Returns the bytes of an asset file.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### getByteArrayFromFilePath

```
public static byte[] getByteArrayFromFilePath(String filePath)
```

Returns the bytes of a file using its file path.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### getCommandsAsList

```
public static ImmutableList<@Player.Command Integer> getCommandsAsList(Player.Commands commands)
```

Returns an `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` with the `https://developer.android.com/reference/androidx/media3/common/Player.Command` contained in `commands`. The contents of the list are in matching order with the `https://developer.android.com/reference/androidx/media3/common/Player.Command` returned by `https://developer.android.com/reference/androidx/media3/common/Player.Commands#get(int)`.

### getEventsAsList

```
public static ImmutableList<@Player.Event Integer> getEventsAsList(Player.Events events)
```

Returns an `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html` with the `https://developer.android.com/reference/androidx/media3/common/Player.Event` contained in `
events`. The contents of the list are in matching order with the `https://developer.android.com/reference/androidx/media3/common/Player.Event` returned by `https://developer.android.com/reference/androidx/media3/common/Player.Events#get(int)`.

### getExtractorInputFromPosition

```
public static ExtractorInput getExtractorInputFromPosition(
    DataSource dataSource,
    long position,
    Uri uri
)
```

Returns an `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` to read from the given input at given position.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### getInMemoryDatabaseProvider

```
public static DatabaseProvider [getInMemoryDatabaseProvider](https://developer.android.com/reference/androidx/media3/test/utils/TestUtil#getInMemoryDatabaseProvider())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/test/utils/InMemoryDatabaseRule`.

### getInnerClass

```
public static @Nullable Class<@NonNull ?> getInnerClass(Class<@NonNull ?> clazz, String className)
```

Returns an inner class of `clazz` called `className` if it exists, otherwise null.

### getInputStream

```
public static InputStream getInputStream(Context context, String fileName)
```

Returns an `https://developer.android.com/reference/java/io/InputStream.html` for reading from an asset file.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### getNonRandomByteBuffer

```
public static ByteBuffer getNonRandomByteBuffer(int frameCount, int bytesPerFrame)
```

Returns a non-random `https://developer.android.com/reference/java/nio/ByteBuffer.html` filled with `frameCount * bytesPerFrame` bytes.

### getPeriodicSamplesBuffer

```
public static ByteBuffer getPeriodicSamplesBuffer(int sampleCount, int period)
```

Returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` filled with alternating 16-bit PCM samples as per the provided period length.

The generated samples alternate between `https://developer.android.com/reference/java/lang/Short.html#MAX_VALUE` and `https://developer.android.com/reference/java/lang/Short.html#MIN_VALUE` every `period / 2` samples.

| Parameters |
|---|---|
| `int sampleCount` | Number of total PCM samples (not frames) to generate. |
| `int period` | Length in PCM samples of one full cycle. |

### getPublicMethods

```
public static List<Method> getPublicMethods(Class<@NonNull ?> clazz)
```

Returns all the public methods of a Java class (except those defined by `https://developer.android.com/reference/java/lang/Object.html`).

### getPublicOverridableMethods

```
public static Iterable<Method> getPublicOverridableMethods(Class<@NonNull ?> clazz)
```

Returns all the public overridable methods of a Java class (except those defined by `https://developer.android.com/reference/java/lang/Object.html`).

### getString

```
public static String getString(Context context, String fileName)
```

Returns a `https://developer.android.com/reference/java/lang/String.html` read from an asset file.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### getThrowingBundle

```
public static Bundle getThrowingBundle()
```

Returns a `https://developer.android.com/reference/android/os/Bundle.html` that will throw an exception at the first attempt to read a value.

### repeatFlakyTest

```
public static void repeatFlakyTest(int maxRepetitions, ThrowingRunnable testImpl)
```

Repeats the potentially flaky test multiple times if needed.

Only use this method for tests with inherent randomness or systems-under-test that are not fully controllable, and where the reason for the the flakiness can be explained. Don't use this method if the test should always pass reliably.

| Parameters |
|---|---|
| `int maxRepetitions` | The maximum number of repetitions before failing the test. |
| `https://junit.org/junit4/javadoc/latest/org/junit/function/ThrowingRunnable.html testImpl` | The test implementation. |

### retrieveTrackFormat

```
public static Format retrieveTrackFormat(
    Context context,
    String fileUri,
    @C.TrackType int trackType
)
```

Returns the `https://developer.android.com/reference/androidx/media3/common/Format` for a given `https://developer.android.com/reference/androidx/media3/common/C.TrackType` from a media file.

If more than one track is present for the given `https://developer.android.com/reference/androidx/media3/common/C.TrackType` then only one track's `https://developer.android.com/reference/androidx/media3/common/Format` is returned.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html`; |
| `https://developer.android.com/reference/java/lang/String.html fileUri` | The media file uri. |
| `@https://developer.android.com/reference/androidx/media3/common/C.TrackType int trackType` | The `https://developer.android.com/reference/androidx/media3/common/C.TrackType`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format` | The `https://developer.android.com/reference/androidx/media3/common/Format` for the given `https://developer.android.com/reference/androidx/media3/common/C.TrackType`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/ExecutionException.html` | If an error occurred while retrieving file's metadata. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` | If interrupted while retrieving file's metadata. |

### seekToTimeUs

```
public static int seekToTimeUs(
    Extractor extractor,
    SeekMap seekMap,
    long seekTimeUs,
    DataSource dataSource,
    FakeTrackOutput trackOutput,
    Uri uri
)
```

Seeks to the given seek time of the stream from the given input, and keeps reading from the input until we can extract at least one sample following the seek position, or until end-of-input is reached.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/Extractor extractor` | The `https://developer.android.com/reference/androidx/media3/extractor/Extractor` to extract from input. |
| `https://developer.android.com/reference/androidx/media3/extractor/SeekMap seekMap` | The `https://developer.android.com/reference/androidx/media3/extractor/SeekMap` of the stream from the given input. |
| `long seekTimeUs` | The seek time, in micro-seconds. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSource` that will be used to read from the input. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput trackOutput` | The `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` to store the extracted samples. |
| `https://developer.android.com/reference/android/net/Uri.html uri` | The Uri of the input. |

| Returns |
|---|---|
| `int` | The index of the first extracted sample written to the given `trackOutput` after the seek is completed, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the seek is completed without any extracted sample. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### timelinesAreSame

```
public static boolean timelinesAreSame(Timeline thisTimeline, Timeline thatTimeline)
```

Returns true if `thisTimeline` is equal to `thatTimeline`, ignoring `https://developer.android.com/reference/androidx/media3/common/Timeline.Window#uid()` and `https://developer.android.com/reference/androidx/media3/common/Timeline.Period#uid()` values, and shuffle order.