docs/doc/reference/com/google/android/exoplayer2/testutil/TestUtil.html
Package com.google.android.exoplayer2.testutil
public classTestUtilextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")
Utility methods for tests.
All Methods Static Methods Concrete Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| static void | assertBitmapsAreSimilar(Bitmap expectedBitmap, Bitmap actualBitmap, double psnrThresholdDb) |
Asserts whether actual bitmap is very similar to the expected bitmap at some quality level.
|
| static void | assertBufferInfosEqual(MediaCodec.BufferInfo expected, MediaCodec.BufferInfo actual) |
Returns whether two BufferInfos are equal.
|
| static void | assertDataSourceContent(DataSource dataSource, DataSpec dataSpec, byte[] expectedData, boolean expectKnownLength) |
Asserts that data read from a DataSource matches expected.
|
| static void | assertTimelinesSame(List<Timeline> actualTimelines, List<Timeline> expectedTimelines) |
Asserts that the actual timelines are the same to the expected timelines.
|
| static Uri | buildAssetUri(String assetPath) |
Returns the Uri for the given asset path.
|
| static byte[] | buildTestData(int length) |
Equivalent to buildTestData(length, length).
|
| static byte[] | buildTestData(int length, int seed) |
Generates an array of random bytes with the specified length.
|
| static byte[] | buildTestData(int length, Random random) |
Generates an array of random bytes with the specified length.
|
| static String | buildTestString(int length, Random random) |
Generates a random string with the specified length.
|
| static byte[] | createByteArray(int... bytes) |
Converts an array of integers in the range [0, 255] into an equivalent byte array.
|
| static ByteBuffer | createByteBuffer(float[] data) |
Creates a ByteBuffer containing the data.
|
| static ByteBuffer | createByteBuffer(short[] data) |
Creates a ByteBuffer containing the data.
|
| static ImmutableList<Byte> | createByteList(int... bytes) |
Converts an array of integers in the range [0, 255] into an equivalent byte list.
|
| static float[] | createFloatArray(ByteBuffer byteBuffer) |
Gets the underlying data of the ByteBuffer as a float[].
|
| static MetadataInputBuffer | createMetadataInputBuffer(byte[] data) |
Create a new MetadataInputBuffer and copy data into the backing ByteBuffer.
|
| static File | createTestFile(File file, long length) |
Writes test data with the specified length to the file and returns it.
|
| static File | createTestFile(File directory, String name) |
Writes one byte long test data to the file and returns it.
|
| static File | createTestFile(File directory, String name, long length) |
Writes test data with the specified length to the file and returns it.
|
| static FakeExtractorOutput | extractAllSamplesFromFile(Extractor extractor, Context context, String fileName) |
Extracts all samples from the given file into a FakeTrackOutput.
|
| static FakeExtractorOutput | extractAllSamplesFromFilePath(Extractor extractor, String filePath) |
Extracts all samples from the given file into a FakeTrackOutput.
|
| static SeekMap | extractSeekMap(Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri) |
Reads from the given input using the given Extractor, until it can produce the SeekMap and all of the track formats have been identified, or until the extractor encounters EOF.
|
| static Bitmap | getBitmap(Context context, String fileName) |
Returns a Bitmap read from an asset file.
|
| static byte[] | getByteArray(Context context, String fileName) |
Returns the bytes of an asset file.
|
| static byte[] | getByteArrayFromFilePath(String filePath) |
Returns the bytes of a file using its file path.
|
| static ExtractorInput | getExtractorInputFromPosition(DataSource dataSource, long position, Uri uri) |
Returns an ExtractorInput to read from the given input at given position.
|
| static DatabaseProvider | getInMemoryDatabaseProvider() |
Returns a DatabaseProvider that provides an in-memory database.
|
| static InputStream | getInputStream(Context context, String fileName) |
Returns an InputStream for reading from an asset file.
|
| static List<Method> | getPublicMethods(Class<?> clazz) |
Returns all the public methods of a Java class (except those defined by Object).
|
| static String | getString(Context context, String fileName) |
Returns a String read from an asset file.
|
| 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.
|
| static boolean | timelinesAreSame(Timeline thisTimeline, Timeline thatTimeline) |
Returns true if thisTimeline is equal to thatTimeline, ignoring Timeline.Window.uid and Timeline.Period.uid values, and shuffle order.
|
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public static byte[] buildTestData(int length)
Equivalent to buildTestData(length, length).
Parameters:length - The length of the array.Returns:The generated array.
-
public static byte[] buildTestData(int length,
int seed)
Generates an array of random bytes with the specified length.
Parameters:length - The length of the array.seed - A seed for an internally created source of randomness.Returns:The generated array.
-
public static byte[] buildTestData(int length,[Random](https://developer.android.com/reference/java/util/Random.html "class or interface in java.util")random)
Generates an array of random bytes with the specified length.
Parameters:length - The length of the array.random - A source of randomness.Returns:The generated array.
-
public static[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")buildTestString(int length,[Random](https://developer.android.com/reference/java/util/Random.html "class or interface in java.util")random)
Generates a random string with the specified length.
Parameters:length - The length of the string.random - A source of randomness.Returns:The generated string.
-
public static byte[] createByteArray(int... bytes)
Converts an array of integers in the range [0, 255] into an equivalent byte array.
Parameters:bytes - An array of integers, all of which must be in the range [0, 255].Returns:The equivalent byte array.
-
public static float[] createFloatArray([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")byteBuffer)
Gets the underlying data of the ByteBuffer as a float[].
-
public static[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")createByteBuffer(float[] data)
Creates a ByteBuffer containing the data.
-
public static[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")createByteBuffer(short[] data)
Creates a ByteBuffer containing the data.
-
public static[ImmutableList](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableList.html?is-external=true "class or interface in com.google.common.collect")<[Byte](https://developer.android.com/reference/java/lang/Byte.html "class or interface in java.lang")> createByteList(int... bytes)
Converts an array of integers in the range [0, 255] into an equivalent byte list.
Parameters:bytes - An array of integers, all of which must be in the range [0, 255].Returns:The equivalent byte list.
-
public static[File](https://developer.android.com/reference/java/io/File.html "class or interface in java.io")createTestFile([File](https://developer.android.com/reference/java/io/File.html?is-external=true "class or interface in java.io")directory,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Writes one byte long test data to the file and returns it.
Throws:IOException
-
public static[File](https://developer.android.com/reference/java/io/File.html "class or interface in java.io")createTestFile([File](https://developer.android.com/reference/java/io/File.html?is-external=true "class or interface in java.io")directory,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name,
long length)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Writes test data with the specified length to the file and returns it.
Throws:IOException
-
public static[File](https://developer.android.com/reference/java/io/File.html "class or interface in java.io")createTestFile([File](https://developer.android.com/reference/java/io/File.html?is-external=true "class or interface in java.io")file,
long length)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Writes test data with the specified length to the file and returns it.
Throws:IOException
-
public static byte[] getByteArray([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")fileName)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns the bytes of an asset file.
Throws:IOException
-
public static byte[] getByteArrayFromFilePath([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")filePath)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns the bytes of a file using its file path.
Throws:IOException
-
public static[InputStream](https://developer.android.com/reference/java/io/InputStream.html "class or interface in java.io")getInputStream([Context](https://developer.android.com/reference/android/content/Context.html?is-external=true "class or interface in android.content")context,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")fileName)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns an InputStream for reading from an asset file.
Throws:IOException
-
public static[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")getString([Context](https://developer.android.com/reference/android/content/Context.html?is-external=true "class or interface in android.content")context,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")fileName)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns a String read from an asset file.
Throws:IOException
-
public static[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")getBitmap([Context](https://developer.android.com/reference/android/content/Context.html?is-external=true "class or interface in android.content")context,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")fileName)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns a Bitmap read from an asset file.
Throws:IOException
-
public static[DatabaseProvider](../database/DatabaseProvider.html "interface in com.google.android.exoplayer2.database")getInMemoryDatabaseProvider()
Returns a DatabaseProvider that provides an in-memory database.
-
public static void assertTimelinesSame([List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[Timeline](../Timeline.html "class in com.google.android.exoplayer2")> actualTimelines,[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[Timeline](../Timeline.html "class in com.google.android.exoplayer2")> 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:actualTimelines - A list of actual timelines.expectedTimelines - A list of expected timelines.
-
public static boolean timelinesAreSame([Timeline](../Timeline.html "class in com.google.android.exoplayer2")thisTimeline,[Timeline](../Timeline.html "class in com.google.android.exoplayer2")thatTimeline)
Returns true if thisTimeline is equal to thatTimeline, ignoring Timeline.Window.uid and Timeline.Period.uid values, and shuffle order.
-
public static void assertDataSourceContent([DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")dataSource,[DataSpec](../upstream/DataSpec.html "class in com.google.android.exoplayer2.upstream")dataSpec,
byte[] expectedData,
boolean expectKnownLength)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Asserts that data read from a DataSource matches expected.
Parameters:dataSource - The DataSource through which to read.dataSpec - The DataSpec to use when opening the DataSource.expectedData - The expected data.expectKnownLength - Whether to assert that DataSource.open(com.google.android.exoplayer2.upstream.DataSpec) returns the expected data length. If false then it's asserted that C.LENGTH_UNSET is returned.Throws:IOException - If an error occurs reading fom the DataSource.
-
public static void assertBufferInfosEqual([MediaCodec.BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html "class or interface in android.media")expected,[MediaCodec.BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html "class or interface in android.media")actual)
Returns whether two BufferInfos are equal.
-
public static void assertBitmapsAreSimilar([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")expectedBitmap,[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html "class or interface in android.graphics")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:expectedBitmap - The expected bitmap.actualBitmap - The actual bitmap.psnrThresholdDb - The PSNR threshold (in dB), at or above which bitmaps are considered very similar.
-
public static[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")buildAssetUri([String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")assetPath)
Returns the Uri for the given asset path.
-
public static[SeekMap](../extractor/SeekMap.html "interface in com.google.android.exoplayer2.extractor")extractSeekMap([Extractor](../extractor/Extractor.html "interface in com.google.android.exoplayer2.extractor")extractor,[FakeExtractorOutput](FakeExtractorOutput.html "class in com.google.android.exoplayer2.testutil")output,[DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")dataSource,[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")uri)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Reads from the given input using the given Extractor, until it can produce the SeekMap and all of the track formats have been identified, or until the extractor encounters EOF.
Parameters:extractor - The Extractor to extractor from input.output - The FakeTrackOutput to store the extracted SeekMap and track.dataSource - The DataSource that will be used to read from the input.uri - The Uri of the input.Returns:The extracted SeekMap.Throws:IOException - If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any SeekMap.
-
public static[FakeExtractorOutput](FakeExtractorOutput.html "class in com.google.android.exoplayer2.testutil")extractAllSamplesFromFile([Extractor](../extractor/Extractor.html "interface in com.google.android.exoplayer2.extractor")extractor,[Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")fileName)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Extracts all samples from the given file into a FakeTrackOutput.
Parameters:extractor - The Extractor to be used.context - A Context.fileName - The name of the input file.Returns:The FakeTrackOutput containing the extracted samples.Throws:IOException - If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any SeekMap.
-
public static[FakeExtractorOutput](FakeExtractorOutput.html "class in com.google.android.exoplayer2.testutil")extractAllSamplesFromFilePath([Extractor](../extractor/Extractor.html "interface in com.google.android.exoplayer2.extractor")extractor,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")filePath)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Extracts all samples from the given file into a FakeTrackOutput.
Parameters:extractor - The Extractor to be used.filePath - The file path.Returns:The FakeTrackOutput containing the extracted samples.Throws:IOException - If an error occurred reading from the input, or if the extractor finishes reading from input without extracting any SeekMap.
-
public static int seekToTimeUs([Extractor](../extractor/Extractor.html "interface in com.google.android.exoplayer2.extractor")extractor,[SeekMap](../extractor/SeekMap.html "interface in com.google.android.exoplayer2.extractor")seekMap,
long seekTimeUs,[DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")dataSource,[FakeTrackOutput](FakeTrackOutput.html "class in com.google.android.exoplayer2.testutil")trackOutput,[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")uri)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
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:extractor - The Extractor to extract from input.seekMap - The SeekMap of the stream from the given input.seekTimeUs - The seek time, in micro-seconds.trackOutput - The FakeTrackOutput to store the extracted samples.dataSource - The DataSource that will be used to read from the input.uri - The Uri of the input.Returns:The index of the first extracted sample written to the given trackOutput after the seek is completed, or C.INDEX_UNSET if the seek is completed without any extracted sample.Throws:IOException
-
public static[ExtractorInput](../extractor/ExtractorInput.html "interface in com.google.android.exoplayer2.extractor")getExtractorInputFromPosition([DataSource](../upstream/DataSource.html "interface in com.google.android.exoplayer2.upstream")dataSource,
long position,[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")uri)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Returns an ExtractorInput to read from the given input at given position.
Throws:IOException
-
public static[MetadataInputBuffer](../metadata/MetadataInputBuffer.html "class in com.google.android.exoplayer2.metadata")createMetadataInputBuffer(byte[] data)
Create a new MetadataInputBuffer and copy data into the backing ByteBuffer.
-
public static[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[Method](https://developer.android.com/reference/java/lang/reflect/Method.html?is-external=true "class or interface in java.lang.reflect")> getPublicMethods([Class](https://developer.android.com/reference/java/lang/Class.html?is-external=true "class or interface in java.lang")<?> clazz)
Returns all the public methods of a Java class (except those defined by Object).