class Util


Miscellaneous utility methods.

Summary

Constants

const String!

Like DEVICE, but in a place where it can be conveniently overridden for local testing.

const String!

A concise description of the device that it can be useful to log for debugging purposes.

const ByteArray<Byte>!

An empty byte array.

const LongArray<Long>!

An empty long array.

const String!

Like MANUFACTURER, but in a place where it can be conveniently overridden for local testing.

const String!

Like MODEL, but in a place where it can be conveniently overridden for local testing.

const Int

Like SDK_INT, but in a place where it can be conveniently overridden for local testing.

Public functions

java-static Long
@UnstableApi
addWithOverflowDefault(x: Long, y: Long, overflowResult: Long)

Returns the sum of two arguments, or a third argument if the result overflows.

java-static Boolean
@UnstableApi
areEqual(o1: Any?, o2: Any?)

Tests two objects for equals equality, handling the case where one or both may be null.

java-static Int
@UnstableApi
binarySearchCeil(
    array: IntArray!,
    value: Int,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the smallest element in array that is greater than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
binarySearchCeil(
    array: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the smallest element in array that is greater than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
<T : Comparable<T!>?> binarySearchCeil(
    list: (Mutable)List<Comparable<T!>!>!,
    value: T!,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the smallest element in list that is greater than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
binarySearchFloor(
    array: IntArray!,
    value: Int,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the largest element in array that is less than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
binarySearchFloor(
    array: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the largest element in array that is less than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
<T : Comparable<T!>?> binarySearchFloor(
    list: (Mutable)List<Comparable<T!>!>!,
    value: T!,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the largest element in list that is less than (or optionally equal to) a specified value.

java-static Int
@UnstableApi
binarySearchFloor(
    longArray: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
)

Returns the index of the largest element in longArray that is less than (or optionally equal to) a specified value.

java-static T!
@UnstableApi
@EnsuresNonNull(value = "#1")
<T> castNonNull(value: T?)

Casts a nullable variable to a non-null variable without runtime null check.

java-static Array<T!>!

Casts a nullable type array to a non-null type array without runtime null check.

java-static Int
@UnstableApi
ceilDivide(numerator: Int, denominator: Int)

Divides a numerator by a denominator, returning the ceiled result.

java-static Long
@UnstableApi
ceilDivide(numerator: Long, denominator: Long)

Divides a numerator by a denominator, returning the ceiled result.

java-static Boolean

Returns whether it may be possible to load the URIs of the given media items based on the network security policy's cleartext traffic permissions.

java-static Unit

Closes a Closeable, suppressing any IOException that may occur.

java-static Int
@UnstableApi
compareLong(left: Long, right: Long)

Compares two long values and returns the same value as Long.compare(long, long).

java-static Float
@UnstableApi
constrainValue(value: Float, min: Float, max: Float)

Constrains a value to the specified bounds.

java-static Int
@UnstableApi
constrainValue(value: Int, min: Int, max: Int)

Constrains a value to the specified bounds.

java-static Long
@UnstableApi
constrainValue(value: Long, min: Long, max: Long)

Constrains a value to the specified bounds.

java-static Boolean
@UnstableApi
contains(@NullableType items: Array<Any!>!, item: Any?)

Tests whether an items array contains an object equal to item, according to equals.

java-static Boolean
@UnstableApi
<T> contains(sparseArray: SparseArray<T!>!, key: Int)

Tests whether a SparseArray contains a given key.

java-static Boolean
@UnstableApi
<T> contentEquals(
    sparseArray1: SparseArray<T!>?,
    sparseArray2: SparseArray<T!>?
)

Tests two SparseArray instances for content equality, handling the case where one or both may be null.

java-static Int
@UnstableApi
<T> contentHashCode(sparseArray: SparseArray<T!>!)

Returns a hash code value for the contents of this SparseArray, combining the hashCode result of all its keys and values.

java-static Int
@UnstableApi
crc16(bytes: ByteArray!, start: Int, end: Int, initialValue: Int)

Returns the result of updating a CRC-16 with the specified bytes in a "most significant bit first" order.

java-static Int
@UnstableApi
crc32(bytes: ByteArray!, start: Int, end: Int, initialValue: Int)

Returns the result of updating a CRC-32 with the specified bytes in a "most significant bit first" order.

java-static Int
@UnstableApi
crc8(bytes: ByteArray!, start: Int, end: Int, initialValue: Int)

Returns the result of updating a CRC-8 with the specified bytes in a "most significant bit first" order.

java-static Handler!

Creates a Handler with the specified Handler.Callback on the specified thread.

java-static Handler!

Creates a Handler on the current Looper thread.

java-static Handler!

Creates a Handler with the specified Handler.Callback on the current thread.

java-static Handler!

Creates a Handler on the current Looper thread.

java-static Handler!

Creates a Handler with the specified Handler.Callback on the current thread.

java-static ByteBuffer!

Returns a read-only view of the given ByteBuffer.

java-static File!

Creates an empty directory in the directory returned by getCacheDir.

java-static File!
@UnstableApi
createTempFile(context: Context!, prefix: String!)

Creates a new empty file in the directory returned by getCacheDir.

java-static Long
@UnstableApi
durationUsToSampleCount(durationUs: Long, sampleRate: Int)

Returns the number of samples required to represent durationUs of media at sampleRate, assuming all samples are equal duration except the last one which may be shorter.

java-static String!

Escapes a string so that it's safe for use as a file or directory name on at least FAT32 filesystems.

java-static Uri!

If the provided URI is an ISM Presentation URI, returns the URI with "Manifest" appended to its path (i.e., the corresponding default manifest URI).

java-static String!
@UnstableApi
formatInvariant(format: String!, args: Array<Any!>!)

Formats a string using US.

java-static String!

Returns a new String constructed by decoding UTF-8 encoded bytes.

java-static String!
@UnstableApi
fromUtf8Bytes(bytes: ByteArray!, offset: Int, length: Int)

Returns a new String constructed by decoding UTF-8 encoded bytes in a subarray.

java-static Int

Returns a newly generated audio session identifier, or ERROR if an error occurred in which case audio playback may fail.

java-static String?

Returns the MIME type corresponding to the given adaptive ContentType, or null if the content type is not adaptive.

java-static Int

Retrieves the API Level that AudioFormat introduced an encoding.

java-static Int

This function is deprecated.

This method is no longer used by the media3 library, it does not work well and should be avoided.

java-static AudioFormat!
@UnstableApi
@RequiresApi(value = 21)
getAudioFormat(sampleRate: Int, channelConfig: Int, encoding: Int)

Creates AudioFormat with given sampleRate, channelConfig, and encoding.

java-static Int

Returns the audio track channel configuration for the given channel count, or CHANNEL_INVALID if output is not possible.

java-static Int

Returns the C.AudioUsage corresponding to the specified C.StreamType.

java-static Player.Commands!
@UnstableApi
getAvailableCommands(
    player: Player!,
    permanentAvailableCommands: Player.Commands!
)

Returns the Commands available in the Player.

java-static Int

Absolute get method for reading an int value in BIG_ENDIAN in a .

java-static ByteArray<Byte>!

Returns a byte array containing values parsed from the hex string provided.

java-static Int

Returns the number of codec strings in codecs whose type matches trackType.

java-static String?

Returns a copy of codecs without the codecs whose track type doesn't match trackType.

java-static String!

Returns a string with comma delimited simple names of each object's class.

java-static String!

Returns the upper-case ISO 3166-1 alpha-2 country code of the current registered operator's MCC (Mobile Country Code), or the country code of the default Locale if not available.

java-static Point!

Gets the size of the current mode of the default display, in pixels.

java-static Point!

Gets the size of the current mode of the specified display, in pixels.

java-static Looper!

Returns the Looper associated with the current thread, or the Looper of the application's main thread if the current thread doesn't have a Looper.

java-static Uri!

Returns a data URI with the specified MIME type and data.

java-static Locale!

Returns the default DISPLAYLocale.

java-static Drawable!
@UnstableApi
getDrawable(
    context: Context!,
    resources: Resources!,
    drawableRes: @DrawableRes Int
)

Returns a Drawable for the given resource or throws a if not found.

java-static UUID?
getDrmUuid(drmScheme: String!)

Derives a DRM UUID from drmScheme.

java-static Int

Returns a PlaybackException.ErrorCode value that corresponds to the provided value.

java-static Int

Attempts to parse an error code from a diagnostic string found in framework media exceptions.

java-static String!

Returns string representation of a C.FormatSupport flag.

java-static Int

Returns the integer equal to the big-endian concatenation of the characters in string as bytes.

java-static String!

Returns the language tag for a Locale.

java-static Int

Returns the number of maximum pending output frames that are allowed on a MediaCodec decoder.

java-static Long

Returns the duration of media that will elapse in playoutDuration.

java-static Long
@UnstableApi
getNowUnixTimeMs(elapsedRealtimeEpochOffsetMs: Long)

Returns the current time in milliseconds since the epoch.

java-static Int

Converts a sample bit depth to a corresponding PCM encoding constant.

java-static Format!

Gets a PCM Format based on the AudioProcessor.AudioFormat.

java-static Format!
@UnstableApi
getPcmFormat(@C.PcmEncoding pcmEncoding: Int, channels: Int, sampleRate: Int)

Gets a PCM Format with the specified parameters.

java-static Int
@UnstableApi
getPcmFrameSize(@C.PcmEncoding pcmEncoding: Int, channelCount: Int)

Returns the frame size for audio with channelCount channels in the specified encoding.

java-static Long

Returns the playout duration of mediaDuration of media.

java-static (Mutable)List<String!>!

Returns a list of strings representing the C.RoleFlags values present in roleFlags.

java-static (Mutable)List<String!>!

Returns a list of strings representing the C.SelectionFlags values present in selectionFlags.

java-static Int

Returns the C.StreamType corresponding to the specified C.AudioUsage.

java-static String!
@UnstableApi
getStringForTime(
    builder: StringBuilder!,
    formatter: Formatter!,
    timeMs: Long
)

Returns the specified millisecond time formatted as a string.

java-static Array<String!>!

Returns a non-empty array of normalized IETF BCP 47 language tags for the system languages ordered by preference.

java-static String!

Returns a string representation of a C.TrackType.

java-static String!
@UnstableApi
getUserAgent(context: Context!, applicationName: String!)

Returns a user agent string based on the given application name and the library version.

java-static ByteArray<Byte>!

Returns a new byte array containing the code points of a String encoded using UTF-8.

java-static ByteArray<Byte>!

Compresses input using gzip and returns the result in a newly allocated byte array.

java-static Boolean

Updates the player to handle an interaction with a pause button.

java-static Boolean

Updates the player to handle an interaction with a play button.

java-static Boolean

Updates the player to handle an interaction with a play or pause button.

java-static Boolean
@UnstableApi
handlePlayPauseButtonAction(player: Player?, playIfSuppressed: Boolean)

Updates the player to handle an interaction with a play or pause button.

java-static Int

This function is deprecated.

Use parse and inferContentType for full file paths or inferContentTypeForExtension for extensions.

java-static Int

Makes a best guess to infer the ContentType from a Uri.

java-static Int
@UnstableApi
@C.ContentType
inferContentType(uri: Uri!, overrideExtension: String?)

This function is deprecated.

Use inferContentTypeForExtension when overrideExtension is non-empty, and inferContentType otherwise.

java-static Int

Makes a best guess to infer the ContentType from a file extension.

java-static Int

Makes a best guess to infer the ContentType from a Uri and optional MIME type.

java-static Boolean
@UnstableApi
inflate(
    input: ParsableByteArray!,
    output: ParsableByteArray!,
    inflater: Inflater?
)

Uncompresses the data in input.

java-static String!

Returns a string representation of the integer using radix value MAX_RADIX.

java-static Boolean

Returns whether the app is running on an automotive device.

java-static Boolean

Returns the image MIME types that can be decoded and loaded by that Media3 aims to support.

java-static Boolean

Returns whether encoding is high resolution (> 16-bit) PCM.

java-static Boolean

Returns whether encoding is one of the linear PCM encodings.

java-static Boolean
java-static Boolean

Returns whether the given character is a carriage return ('\r') or a line feed ('\n').

java-static Boolean

Returns true if the URI is a path to a local file or a reference to a local file.

java-static Boolean

Returns true if the code path is currently running on an emulator.

java-static Boolean

Returns whether the app is running on a TV device.

java-static Boolean

Returns whether the app is running on a Wear OS device.

java-static Int
@UnstableApi
linearSearch(array: IntArray!, value: Int)

Returns the index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

java-static Int

Returns the index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

java-static String!
@UnstableApi
loadAsset(context: Context!, assetPath: String!)

Loads a file from the assets folder.

java-static Long
@UnstableApi
@RequiresApi(value = 18)
maxValue(sparseLongArray: SparseLongArray!)

Returns the maximum value in the given SparseLongArray.

java-static Boolean
maybeRequestReadExternalStoragePermission(
    activity: Activity!,
    mediaItems: Array<MediaItem!>!
)

This function is deprecated.

Use maybeRequestReadStoragePermission instead.

java-static Boolean
maybeRequestReadExternalStoragePermission(
    activity: Activity!,
    uris: Array<Uri!>!
)

This function is deprecated.

Use maybeRequestReadStoragePermission instead.

java-static Boolean
maybeRequestReadStoragePermission(
    activity: Activity!,
    mediaItems: Array<MediaItem!>!
)

Checks whether it's necessary to request storage reading permissions for the specified media items, requesting the permissions if necessary.

java-static Long
@UnstableApi
@RequiresApi(value = 18)
minValue(sparseLongArray: SparseLongArray!)

Returns the minimum value in the given SparseLongArray.

java-static Unit
@UnstableApi
<T : Any?> moveItems(
    items: (Mutable)List<T!>!,
    fromIndex: Int,
    toIndex: Int,
    newFromIndex: Int
)

Moves the elements starting at fromIndex to newFromIndex.

java-static Long

Converts a time in milliseconds to the corresponding time in microseconds, preserving TIME_UNSET values and TIME_END_OF_SOURCE values.

java-static ExecutorService!

Instantiates a new single threaded executor whose thread has the specified name.

java-static ScheduledExecutorService!

Instantiates a new single threaded scheduled executor whose thread has the specified name.

java-static @PolyNull String!

Returns a normalized IETF BCP 47 language tag for language.

java-static Array<T!>!
@UnstableApi
<T> nullSafeArrayAppend(original: Array<T!>!, newElement: T!)

Creates a new array containing original with newElement appended.

java-static Array<T!>!
@UnstableApi
<T> nullSafeArrayConcatenation(first: Array<T!>!, second: Array<T!>!)

Creates a new array containing the concatenation of two non-null type arrays.

java-static Array<T!>!
@UnstableApi
<T> nullSafeArrayCopy(input: Array<T!>!, length: Int)

Copies and optionally truncates an array.

java-static Array<T!>!
@UnstableApi
<T> nullSafeArrayCopyOfRange(input: Array<T!>!, from: Int, to: Int)

Copies a subset of an array.

java-static Unit
@UnstableApi
<T> nullSafeListToArray(list: (Mutable)List<T!>!, array: Array<T!>!)

Copies the contents of list into array.

java-static Long

Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since the epoch.

java-static Long

Parses an xs:duration attribute value, returning the parsed duration in milliseconds.

java-static Boolean
@UnstableApi
postOrRun(handler: Handler!, runnable: Runnable!)

Posts the Runnable if the calling thread differs with the Looper of the .

java-static ListenableFuture<T!>!
@UnstableApi
<T> postOrRunWithCompletion(
    handler: Handler!,
    runnable: Runnable!,
    successValue: T!
)

Posts the Runnable if the calling thread differs with the Looper of the .

java-static Boolean

Reads an integer from a Parcel and interprets it as a boolean, with 0 mapping to false and all other values mapping to true.

java-static Unit
@UnstableApi
recursiveDelete(fileOrDirectory: File!)

Recursively deletes a directory and its content.

java-static Intent?
@UnstableApi
registerReceiverNotExported(
    context: Context!,
    receiver: BroadcastReceiver?,
    filter: IntentFilter!
)

Registers a BroadcastReceiver that's not intended to receive broadcasts from other apps.

java-static Unit
@UnstableApi
<T> removeRange(list: (Mutable)List<T!>!, fromIndex: Int, toIndex: Int)

Removes an indexed range from a List.

java-static Long
@UnstableApi
sampleCountToDurationUs(sampleCount: Long, sampleRate: Int)

Returns the total duration (in microseconds) of sampleCount samples of equal duration at sampleRate.

java-static Long
@UnstableApi
scaleLargeTimestamp(timestamp: Long, multiplier: Long, divisor: Long)

Scales a large timestamp.

java-static LongArray<Long>!
@UnstableApi
scaleLargeTimestamps(
    timestamps: (Mutable)List<Long!>!,
    multiplier: Long,
    divisor: Long
)

Applies scaleLargeTimestamp to a list of unscaled timestamps.

java-static Unit
@UnstableApi
scaleLargeTimestampsInPlace(
    timestamps: LongArray!,
    multiplier: Long,
    divisor: Long
)

Applies scaleLargeTimestamp to an array of unscaled timestamps.

java-static Long
@UnstableApi
scaleLargeValue(
    value: Long,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
)

Scales a large value by a multiplier and a divisor.

java-static LongArray<Long>!
@UnstableApi
scaleLargeValues(
    values: (Mutable)List<Long!>!,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
)

Applies scaleLargeValue to a list of unscaled values.

java-static Unit
@UnstableApi
scaleLargeValuesInPlace(
    values: LongArray!,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
)

Applies scaleLargeValue to an array of unscaled values.

java-static Unit
@UnstableApi
setForegroundServiceNotification(
    service: Service!,
    notificationId: Int,
    notification: Notification!,
    foregroundServiceType: Int,
    foregroundServiceManifestType: String!
)

Sets the notification required for a foreground service.

java-static Boolean
@EnsuresNonNullIf(result = false, expression = "#1")
shouldShowPlayButton(player: Player?)

Returns whether a play button should be presented on a UI element for playback control.

java-static Boolean
@UnstableApi
@EnsuresNonNullIf(result = false, expression = "#1")
shouldShowPlayButton(player: Player?, playIfSuppressed: Boolean)

Returns whether a play button should be presented on a UI element for playback control.

java-static Unit

A hacky method that always throws t even if t is a checked exception, and is not declared to be thrown.

java-static Array<String!>!
@UnstableApi
split(value: String!, regex: String!)

Splits a string using value.split(regex, -1).

java-static Array<String!>!
@UnstableApi
splitAtFirst(value: String!, regex: String!)

Splits the string at the first occurrence of the delimiter regex.

java-static Array<String!>!

Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.

java-static ComponentName?

Calls startForegroundService if SDK_INT is 26 or higher, or startService otherwise.

java-static Long
@UnstableApi
subtractWithOverflowDefault(x: Long, y: Long, overflowResult: Long)

Returns the difference between two arguments, or a third argument if the result overflows.

java-static Long

Returns the sum of all summands of the given array.

java-static Boolean
@UnstableApi
tableExists(database: SQLiteDatabase!, tableName: String!)

Returns whether the table exists in the database.

java-static ByteArray<Byte>!

Converts the entirety of an InputStream to a byte array.

java-static ByteArray<Byte>!

Converts a float into an equivalent byte array.

java-static ByteArray<Byte>!

Converts an integer into an equivalent byte array.

java-static ByteArray<Byte>!

Converts an array of integers into an equivalent byte array.

java-static Float

Converts a byte array into a float.

java-static String!

Returns a string containing a lower-case hex representation of the bytes provided.

java-static Int

Converts a byte array into an integer.

java-static Long
@UnstableApi
toLong(mostSignificantBits: Int, leastSignificantBits: Int)

Returns the long that is composed of the bits of the 2 specified integers.

java-static Long

Converts an integer to a long by unsigned conversion.

java-static ListenableFuture<T!>!
@UnstableApi
<T, U> transformFutureAsync(
    future: ListenableFuture<U!>!,
    transformFunction: AsyncFunction<U!, T!>!
)

Asynchronously transforms the result of a ListenableFuture.

java-static String?

Unescapes an escaped file or directory name back to its original value.

java-static Long

Converts a time in microseconds to the corresponding time in milliseconds, preserving TIME_UNSET and TIME_END_OF_SOURCE values.

java-static Unit
@UnstableApi
writeBoolean(parcel: Parcel!, value: Boolean)

Writes a boolean to a Parcel.

Constants

DEVICE

@UnstableApi
const val DEVICEString!

Like DEVICE, but in a place where it can be conveniently overridden for local testing.

DEVICE_DEBUG_INFO

@UnstableApi
const val DEVICE_DEBUG_INFOString!

A concise description of the device that it can be useful to log for debugging purposes.

EMPTY_BYTE_ARRAY

@UnstableApi
const val EMPTY_BYTE_ARRAYByteArray<Byte>!

An empty byte array.

EMPTY_LONG_ARRAY

@UnstableApi
const val EMPTY_LONG_ARRAYLongArray<Long>!

An empty long array.

MANUFACTURER

@UnstableApi
const val MANUFACTURERString!

Like MANUFACTURER, but in a place where it can be conveniently overridden for local testing.

MODEL

@UnstableApi
const val MODELString!

Like MODEL, but in a place where it can be conveniently overridden for local testing.

SDK_INT

@UnstableApi
const val SDK_INTInt

Like SDK_INT, but in a place where it can be conveniently overridden for local testing.

Public functions

addWithOverflowDefault

@UnstableApi
java-static fun addWithOverflowDefault(x: Long, y: Long, overflowResult: Long): Long

Returns the sum of two arguments, or a third argument if the result overflows.

Parameters
x: Long

The first value.

y: Long

The second value.

overflowResult: Long

The return value if x + y overflows.

Returns
Long

x + y, or overflowResult if the result overflows.

areEqual

@UnstableApi
java-static fun areEqual(o1: Any?, o2: Any?): Boolean

Tests two objects for equals equality, handling the case where one or both may be null.

Parameters
o1: Any?

The first object.

o2: Any?

The second object.

Returns
Boolean

o1 == null ? o2 == null : o1.equals(o2).

binarySearchCeil

@UnstableApi
java-static fun binarySearchCeil(
    array: IntArray!,
    value: Int,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the smallest element in array that is greater than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the array must be sorted. If the array contains multiple elements equal to value and inclusive is true, the index of the last one will be returned.

Parameters
array: IntArray!

The array to search.

value: Int

The value being searched for.

inclusive: Boolean

If the value is present in the array, whether to return the corresponding index. If false then the returned index corresponds to the smallest element strictly greater than the value.

stayInBounds: Boolean

If true, then (a.length - 1) will be returned in the case that the value is greater than the largest element in the array. If false then a.length will be returned.

Returns
Int

The index of the smallest element in array that is greater than (or optionally equal to) value.

binarySearchCeil

@UnstableApi
java-static fun binarySearchCeil(
    array: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the smallest element in array that is greater than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the array must be sorted. If the array contains multiple elements equal to value and inclusive is true, the index of the last one will be returned.

Parameters
array: LongArray!

The array to search.

value: Long

The value being searched for.

inclusive: Boolean

If the value is present in the array, whether to return the corresponding index. If false then the returned index corresponds to the smallest element strictly greater than the value.

stayInBounds: Boolean

If true, then (a.length - 1) will be returned in the case that the value is greater than the largest element in the array. If false then a.length will be returned.

Returns
Int

The index of the smallest element in array that is greater than (or optionally equal to) value.

binarySearchCeil

@UnstableApi
java-static fun <T : Comparable<T!>?> binarySearchCeil(
    list: (Mutable)List<Comparable<T!>!>!,
    value: T!,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the smallest element in list that is greater than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the list must be sorted. If the list contains multiple elements equal to value and inclusive is true, the index of the last one will be returned.

Parameters
<T : Comparable<T!>?>

The type of values being searched.

list: (Mutable)List<Comparable<T!>!>!

The list to search.

value: T!

The value being searched for.

inclusive: Boolean

If the value is present in the list, whether to return the corresponding index. If false then the returned index corresponds to the smallest element strictly greater than the value.

stayInBounds: Boolean

If true, then (list.size() - 1) will be returned in the case that the value is greater than the largest element in the list. If false then list.size() will be returned.

Returns
Int

The index of the smallest element in list that is greater than (or optionally equal to) value.

binarySearchFloor

@UnstableApi
java-static fun binarySearchFloor(
    array: IntArray!,
    value: Int,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the largest element in array that is less than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the array must be sorted. If the array contains multiple elements equal to value and inclusive is true, the index of the first one will be returned.

Parameters
array: IntArray!

The array to search.

value: Int

The value being searched for.

inclusive: Boolean

If the value is present in the array, whether to return the corresponding index. If false then the returned index corresponds to the largest element strictly less than the value.

stayInBounds: Boolean

If true, then 0 will be returned in the case that the value is smaller than the smallest element in the array. If false then -1 will be returned.

Returns
Int

The index of the largest element in array that is less than (or optionally equal to) value.

binarySearchFloor

@UnstableApi
java-static fun binarySearchFloor(
    array: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the largest element in array that is less than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the array must be sorted. If the array contains multiple elements equal to value and inclusive is true, the index of the first one will be returned.

Parameters
array: LongArray!

The array to search.

value: Long

The value being searched for.

inclusive: Boolean

If the value is present in the array, whether to return the corresponding index. If false then the returned index corresponds to the largest element strictly less than the value.

stayInBounds: Boolean

If true, then 0 will be returned in the case that the value is smaller than the smallest element in the array. If false then -1 will be returned.

Returns
Int

The index of the largest element in array that is less than (or optionally equal to) value.

binarySearchFloor

@UnstableApi
java-static fun <T : Comparable<T!>?> binarySearchFloor(
    list: (Mutable)List<Comparable<T!>!>!,
    value: T!,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the largest element in list that is less than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the list must be sorted. If the list contains multiple elements equal to value and inclusive is true, the index of the first one will be returned.

Parameters
<T : Comparable<T!>?>

The type of values being searched.

list: (Mutable)List<Comparable<T!>!>!

The list to search.

value: T!

The value being searched for.

inclusive: Boolean

If the value is present in the list, whether to return the corresponding index. If false then the returned index corresponds to the largest element strictly less than the value.

stayInBounds: Boolean

If true, then 0 will be returned in the case that the value is smaller than the smallest element in the list. If false then -1 will be returned.

Returns
Int

The index of the largest element in list that is less than (or optionally equal to) value.

binarySearchFloor

@UnstableApi
java-static fun binarySearchFloor(
    longArray: LongArray!,
    value: Long,
    inclusive: Boolean,
    stayInBounds: Boolean
): Int

Returns the index of the largest element in longArray that is less than (or optionally equal to) a specified value.

The search is performed using a binary search algorithm, so the array must be sorted. If the array contains multiple elements equal to value and inclusive is true, the index of the first one will be returned.

Parameters
longArray: LongArray!

The array to search.

value: Long

The value being searched for.

inclusive: Boolean

If the value is present in the array, whether to return the corresponding index. If false then the returned index corresponds to the largest element strictly less than the value.

stayInBounds: Boolean

If true, then 0 will be returned in the case that the value is smaller than the smallest element in the array. If false then -1 will be returned.

Returns
Int

The index of the largest element in array that is less than (or optionally equal to) value.

castNonNull

@UnstableApi
@EnsuresNonNull(value = "#1")
java-static fun <T> castNonNull(value: T?): T!

Casts a nullable variable to a non-null variable without runtime null check.

Use checkNotNull to throw if the value is null.

castNonNullTypeArray

@UnstableApi
@EnsuresNonNull(value = "#1")
java-static fun <T> castNonNullTypeArray(@NullableType value: Array<@NullableType T!>!): Array<T!>!

Casts a nullable type array to a non-null type array without runtime null check.

ceilDivide

@UnstableApi
java-static fun ceilDivide(numerator: Int, denominator: Int): Int

Divides a numerator by a denominator, returning the ceiled result.

Parameters
numerator: Int

The numerator to divide.

denominator: Int

The denominator to divide by.

Returns
Int

The ceiled result of the division.

ceilDivide

@UnstableApi
java-static fun ceilDivide(numerator: Long, denominator: Long): Long

Divides a numerator by a denominator, returning the ceiled result.

Parameters
numerator: Long

The numerator to divide.

denominator: Long

The denominator to divide by.

Returns
Long

The ceiled result of the division.

checkCleartextTrafficPermitted

java-static fun checkCleartextTrafficPermitted(mediaItems: Array<MediaItem!>!): Boolean

Returns whether it may be possible to load the URIs of the given media items based on the network security policy's cleartext traffic permissions.

Parameters
mediaItems: Array<MediaItem!>!

A list of media items.

Returns
Boolean

Whether it may be possible to load the URIs of the given media items.

closeQuietly

@UnstableApi
java-static fun closeQuietly(closeable: Closeable?): Unit

Closes a Closeable, suppressing any IOException that may occur. Both and InputStream are Closeable.

Parameters
closeable: Closeable?

The Closeable to close.

compareLong

@UnstableApi
java-static fun compareLong(left: Long, right: Long): Int

Compares two long values and returns the same value as Long.compare(long, long).

Parameters
left: Long

The left operand.

right: Long

The right operand.

Returns
Int

0, if left == right, a negative value if left right.

constrainValue

@UnstableApi
java-static fun constrainValue(value: Float, min: Float, max: Float): Float

Constrains a value to the specified bounds.

Parameters
value: Float

The value to constrain.

min: Float

The lower bound.

max: Float

The upper bound.

Returns
Float

The constrained value Math.max(min, Math.min(value, max)).

constrainValue

@UnstableApi
java-static fun constrainValue(value: Int, min: Int, max: Int): Int

Constrains a value to the specified bounds.

Parameters
value: Int

The value to constrain.

min: Int

The lower bound.

max: Int

The upper bound.

Returns
Int

The constrained value Math.max(min, Math.min(value, max)).

constrainValue

@UnstableApi
java-static fun constrainValue(value: Long, min: Long, max: Long): Long

Constrains a value to the specified bounds.

Parameters
value: Long

The value to constrain.

min: Long

The lower bound.

max: Long

The upper bound.

Returns
Long

The constrained value Math.max(min, Math.min(value, max)).

contains

@UnstableApi
java-static fun contains(@NullableType items: Array<Any!>!, item: Any?): Boolean

Tests whether an items array contains an object equal to item, according to equals.

If item is null then true is returned if and only if items contains null.

Parameters
@NullableType items: Array<Any!>!

The array of items to search.

item: Any?

The item to search for.

Returns
Boolean

True if the array contains an object equal to the item being searched for.

contains

@UnstableApi
java-static fun <T> contains(sparseArray: SparseArray<T!>!, key: Int): Boolean

Tests whether a SparseArray contains a given key.

This implements SparseArray#contains for lower API versions.

contentEquals

@UnstableApi
java-static fun <T> contentEquals(
    sparseArray1: SparseArray<T!>?,
    sparseArray2: SparseArray<T!>?
): Boolean

Tests two SparseArray instances for content equality, handling the case where one or both may be null.

Parameters
sparseArray1: SparseArray<T!>?

The first SparseArray instance.

sparseArray2: SparseArray<T!>?

The second SparseArray instance.

Returns
Boolean

True if the two SparseArray instances are equal in contents.

See also
contentEquals

contentHashCode

@UnstableApi
java-static fun <T> contentHashCode(sparseArray: SparseArray<T!>!): Int

Returns a hash code value for the contents of this SparseArray, combining the hashCode result of all its keys and values.

Parameters
sparseArray: SparseArray<T!>!

The SparseArray instance.

Returns
Int

The hash code.

See also
contentHashCode

crc16

@UnstableApi
java-static fun crc16(bytes: ByteArray!, start: Int, end: Int, initialValue: Int): Int

Returns the result of updating a CRC-16 with the specified bytes in a "most significant bit first" order.

Parameters
bytes: ByteArray!

Array containing the bytes to update the crc value with.

start: Int

The start index (inclusive) of the byte range to update the crc with.

end: Int

The end index (exclusive) of the byte range to update the crc with.

initialValue: Int

The initial value for the crc calculation. The lower 16 bits of this 32-bit integer are used for the CRC computation.

Returns
Int

The result of updating the initial value with the specified bytes.

crc32

@UnstableApi
java-static fun crc32(bytes: ByteArray!, start: Int, end: Int, initialValue: Int): Int

Returns the result of updating a CRC-32 with the specified bytes in a "most significant bit first" order.

Parameters
bytes: ByteArray!

Array containing the bytes to update the crc value with.

start: Int

The index to the first byte in the byte range to update the crc with.

end: Int

The index after the last byte in the byte range to update the crc with.

initialValue: Int

The initial value for the crc calculation.

Returns
Int

The result of updating the initial value with the specified bytes.

crc8

@UnstableApi
java-static fun crc8(bytes: ByteArray!, start: Int, end: Int, initialValue: Int): Int

Returns the result of updating a CRC-8 with the specified bytes in a "most significant bit first" order.

Parameters
bytes: ByteArray!

Array containing the bytes to update the crc value with.

start: Int

The index to the first byte in the byte range to update the crc with.

end: Int

The index after the last byte in the byte range to update the crc with.

initialValue: Int

The initial value for the crc calculation.

Returns
Int

The result of updating the initial value with the specified bytes.

createHandler

@UnstableApi
java-static fun createHandler(
    looper: Looper!,
    callback: @UnknownInitialization Handler.Callback?
): Handler!

Creates a Handler with the specified Handler.Callback on the specified thread.

The method accepts partially initialized objects as callback under the assumption that the Handler won't be used to send messages until the callback is fully initialized.

Parameters
looper: Looper!

A Looper to run the callback on.

callback: @UnknownInitialization Handler.Callback?

A Handler.Callback. May be a partially initialized class, or null if no callback is required.

Returns
Handler!

A Handler with the specified callback on the current Looper thread.

createHandlerForCurrentLooper

@UnstableApi
java-static fun createHandlerForCurrentLooper(): Handler!

Creates a Handler on the current Looper thread.

Throws
java.lang.IllegalStateException

If the current thread doesn't have a Looper.

createHandlerForCurrentLooper

@UnstableApi
java-static fun createHandlerForCurrentLooper(
    callback: @UnknownInitialization Handler.Callback?
): Handler!

Creates a Handler with the specified Handler.Callback on the current thread.

The method accepts partially initialized objects as callback under the assumption that the Handler won't be used to send messages until the callback is fully initialized.

Parameters
callback: @UnknownInitialization Handler.Callback?

A Handler.Callback. May be a partially initialized class, or null if no callback is required.

Returns
Handler!

A Handler with the specified callback on the current Looper thread.

Throws
java.lang.IllegalStateException

If the current thread doesn't have a Looper.

createHandlerForCurrentOrMainLooper

@UnstableApi
java-static fun createHandlerForCurrentOrMainLooper(): Handler!

Creates a Handler on the current Looper thread.

If the current thread doesn't have a Looper, the application's main thread is used.

createHandlerForCurrentOrMainLooper

@UnstableApi
java-static fun createHandlerForCurrentOrMainLooper(
    callback: @UnknownInitialization Handler.Callback?
): Handler!

Creates a Handler with the specified Handler.Callback on the current thread.

The method accepts partially initialized objects as callback under the assumption that the Handler won't be used to send messages until the callback is fully initialized.

If the current thread doesn't have a Looper, the application's main thread is used.

Parameters
callback: @UnknownInitialization Handler.Callback?

A Handler.Callback. May be a partially initialized class, or null if no callback is required.

Returns
Handler!

A Handler with the specified callback on the current Looper thread.

createReadOnlyByteBuffer

@UnstableApi
java-static fun createReadOnlyByteBuffer(byteBuffer: ByteBuffer!): ByteBuffer!

Returns a read-only view of the given ByteBuffer.

This behaves the same as asReadOnlyBuffer whilst preserving the of the original buffer.

createTempDirectory

@UnstableApi
java-static fun createTempDirectory(context: Context!, prefix: String!): File!

Creates an empty directory in the directory returned by getCacheDir.

createTempFile

@UnstableApi
java-static fun createTempFile(context: Context!, prefix: String!): File!

Creates a new empty file in the directory returned by getCacheDir.

durationUsToSampleCount

@UnstableApi
java-static fun durationUsToSampleCount(durationUs: Long, sampleRate: Int): Long

Returns the number of samples required to represent durationUs of media at sampleRate, assuming all samples are equal duration except the last one which may be shorter.

The result of this method cannot be generally reversed to the original duration with sampleCountToDurationUs, due to information lost when rounding to a whole number of samples.

Parameters
durationUs: Long

The duration in microseconds.

sampleRate: Int

The sample rate in samples per second.

Returns
Long

The number of samples required to represent durationUs.

escapeFileName

@UnstableApi
java-static fun escapeFileName(fileName: String!): String!

Escapes a string so that it's safe for use as a file or directory name on at least FAT32 filesystems. FAT32 is the most restrictive of all filesystems still commonly used today.

For simplicity, this only handles common characters known to be illegal on FAT32: <, >, :, ", /, \, |, ?, and *. % is also escaped since it is used as the escape character. Escaping is performed in a consistent way so that no collisions occur and unescapeFileName can be used to retrieve the original file name.

Parameters
fileName: String!

File name to be escaped.

Returns
String!

An escaped file name which will be safe for use on at least FAT32 filesystems.

fixSmoothStreamingIsmManifestUri

@UnstableApi
java-static fun fixSmoothStreamingIsmManifestUri(uri: Uri!): Uri!

If the provided URI is an ISM Presentation URI, returns the URI with "Manifest" appended to its path (i.e., the corresponding default manifest URI). Else returns the provided URI without modification. See [MS-SSTR] v20180912, section 2.2.1.

Parameters
uri: Uri!

The original URI.

Returns
Uri!

The fixed URI.

formatInvariant

@UnstableApi
java-static fun formatInvariant(format: String!, args: Array<Any!>!): String!

Formats a string using US.

See also
format

fromUtf8Bytes

@UnstableApi
java-static fun fromUtf8Bytes(bytes: ByteArray!): String!

Returns a new String constructed by decoding UTF-8 encoded bytes.

Parameters
bytes: ByteArray!

The UTF-8 encoded bytes to decode.

Returns
String!

The string.

fromUtf8Bytes

@UnstableApi
java-static fun fromUtf8Bytes(bytes: ByteArray!, offset: Int, length: Int): String!

Returns a new String constructed by decoding UTF-8 encoded bytes in a subarray.

Parameters
bytes: ByteArray!

The UTF-8 encoded bytes to decode.

offset: Int

The index of the first byte to decode.

length: Int

The number of bytes to decode.

Returns
String!

The string.

generateAudioSessionIdV21

@UnstableApi
@RequiresApi(value = 21)
java-static fun generateAudioSessionIdV21(context: Context!): Int

Returns a newly generated audio session identifier, or ERROR if an error occurred in which case audio playback may fail.

getAdaptiveMimeTypeForContentType

java-static fun getAdaptiveMimeTypeForContentType(@C.ContentType contentType: Int): String?

Returns the MIME type corresponding to the given adaptive ContentType, or null if the content type is not adaptive.

getApiLevelThatAudioFormatIntroducedAudioEncoding

@UnstableApi
java-static fun getApiLevelThatAudioFormatIntroducedAudioEncoding(encoding: Int): Int

Retrieves the API Level that AudioFormat introduced an encoding.

Method returns MAX_VALUE if the encoding is unknown.

Parameters
encoding: Int

for which to get the API level.

getAudioContentTypeForStreamType

@UnstableApi
@C.AudioContentType
java-static fun getAudioContentTypeForStreamType(@C.StreamType streamType: Int): Int

getAudioFormat

@UnstableApi
@RequiresApi(value = 21)
java-static fun getAudioFormat(sampleRate: Int, channelConfig: Int, encoding: Int): AudioFormat!

Creates AudioFormat with given sampleRate, channelConfig, and encoding.

getAudioTrackChannelConfig

@UnstableApi
java-static fun getAudioTrackChannelConfig(channelCount: Int): Int

Returns the audio track channel configuration for the given channel count, or CHANNEL_INVALID if output is not possible.

Parameters
channelCount: Int

The number of channels in the input audio.

Returns
Int

The channel configuration or CHANNEL_INVALID if output is not possible.

getAudioUsageForStreamType

@UnstableApi
@C.AudioUsage
java-static fun getAudioUsageForStreamType(@C.StreamType streamType: Int): Int

Returns the C.AudioUsage corresponding to the specified C.StreamType.

getAvailableCommands

@UnstableApi
java-static fun getAvailableCommands(
    player: Player!,
    permanentAvailableCommands: Player.Commands!
): Player.Commands!

Returns the Commands available in the Player.

Parameters
player: Player!

The Player.

permanentAvailableCommands: Player.Commands!

The commands permanently available in the player.

Returns
Player.Commands!

The available Commands.

getBigEndianInt

@UnstableApi
java-static fun getBigEndianInt(buffer: ByteBuffer!, index: Int): Int

Absolute get method for reading an int value in BIG_ENDIAN in a . Same as getInt except the buffer's order as returned by order is ignored and BIG_ENDIAN is used instead.

Parameters
buffer: ByteBuffer!

The buffer from which to read an int in big endian.

index: Int

The index from which the bytes will be read.

Returns
Int

The int value at the given index with the buffer bytes ordered most significant to least significant.

getBytesFromHexString

@UnstableApi
java-static fun getBytesFromHexString(hexString: String!): ByteArray<Byte>!

Returns a byte array containing values parsed from the hex string provided.

Parameters
hexString: String!

The hex string to convert to bytes.

Returns
ByteArray<Byte>!

A byte array containing values parsed from the hex string provided.

getCodecCountOfType

@UnstableApi
java-static fun getCodecCountOfType(codecs: String?, @C.TrackType trackType: Int): Int

Returns the number of codec strings in codecs whose type matches trackType.

getCodecsOfType

@UnstableApi
java-static fun getCodecsOfType(codecs: String?, @C.TrackType trackType: Int): String?

Returns a copy of codecs without the codecs whose track type doesn't match trackType.

Parameters
codecs: String?

A codec sequence string, as defined in RFC 6381.

@C.TrackType trackType: Int

The track type.

Returns
String?

A copy of codecs without the codecs whose track type doesn't match trackType. If this ends up empty, or codecs is null, returns null.

getCommaDelimitedSimpleClassNames

@UnstableApi
java-static fun getCommaDelimitedSimpleClassNames(objects: Array<Any!>!): String!

Returns a string with comma delimited simple names of each object's class.

Parameters
objects: Array<Any!>!

The objects whose simple class names should be comma delimited and returned.

Returns
String!

A string with comma delimited simple names of each object's class.

getCountryCode

@UnstableApi
java-static fun getCountryCode(context: Context?): String!

Returns the upper-case ISO 3166-1 alpha-2 country code of the current registered operator's MCC (Mobile Country Code), or the country code of the default Locale if not available.

Parameters
context: Context?

A context to access the telephony service. If null, only the Locale can be used.

Returns
String!

The upper-case ISO 3166-1 alpha-2 country code, or an empty String if unavailable.

getCurrentDisplayModeSize

@UnstableApi
java-static fun getCurrentDisplayModeSize(context: Context!): Point!

Gets the size of the current mode of the default display, in pixels.

Note that due to application UI scaling, the number of pixels made available to applications (as reported by getSize may differ from the mode's actual resolution (as reported by this function). For example, applications running on a display configured with a 4K mode may have their UI laid out and rendered in 1080p and then scaled up. Applications can take advantage of the full mode resolution through a SurfaceView using full size buffers.

Parameters
context: Context!

Any context.

Returns
Point!

The size of the current mode, in pixels.

getCurrentDisplayModeSize

@UnstableApi
java-static fun getCurrentDisplayModeSize(context: Context!, display: Display!): Point!

Gets the size of the current mode of the specified display, in pixels.

Note that due to application UI scaling, the number of pixels made available to applications (as reported by getSize may differ from the mode's actual resolution (as reported by this function). For example, applications running on a display configured with a 4K mode may have their UI laid out and rendered in 1080p and then scaled up. Applications can take advantage of the full mode resolution through a SurfaceView using full size buffers.

Parameters
context: Context!

Any context.

display: Display!

The display whose size is to be returned.

Returns
Point!

The size of the current mode, in pixels.

getCurrentOrMainLooper

@UnstableApi
java-static fun getCurrentOrMainLooper(): Looper!

Returns the Looper associated with the current thread, or the Looper of the application's main thread if the current thread doesn't have a Looper.

getDataUriForString

@UnstableApi
java-static fun getDataUriForString(mimeType: String!, data: String!): Uri!

Returns a data URI with the specified MIME type and data.

getDefaultDisplayLocale

@UnstableApi
java-static fun getDefaultDisplayLocale(): Locale!

Returns the default DISPLAYLocale.

getDrawable

@UnstableApi
java-static fun getDrawable(
    context: Context!,
    resources: Resources!,
    drawableRes: @DrawableRes Int
): Drawable!

Returns a Drawable for the given resource or throws a if not found.

Parameters
context: Context!

The context to get the theme from starting with API 21.

resources: Resources!

The resources to load the drawable from.

drawableRes: @DrawableRes Int

The drawable resource int.

Returns
Drawable!

The loaded Drawable.

getDrmUuid

java-static fun getDrmUuid(drmScheme: String!): UUID?

Derives a DRM UUID from drmScheme.

Parameters
drmScheme: String!

A UUID string, or "widevine", "playready" or "clearkey".

Returns
UUID?

The derived UUID, or null if one could not be derived.

getErrorCodeForMediaDrmErrorCode

@UnstableApi
@PlaybackException.ErrorCode
java-static fun getErrorCodeForMediaDrmErrorCode(mediaDrmErrorCode: Int): Int

Returns a PlaybackException.ErrorCode value that corresponds to the provided value. Returns ERROR_CODE_DRM_SYSTEM_ERROR if the provided error code isn't recognised.

getErrorCodeFromPlatformDiagnosticsInfo

@UnstableApi
java-static fun getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo: String?): Int

Attempts to parse an error code from a diagnostic string found in framework media exceptions.

For example: android.media.MediaCodec.error_1 or android.media.MediaDrm.error_neg_2.

Parameters
diagnosticsInfo: String?

A string from which to parse the error code.

Returns
Int

The parsed error code, or 0 if an error code could not be parsed.

getFormatSupportString

@UnstableApi
java-static fun getFormatSupportString(@C.FormatSupport formatSupport: Int): String!

Returns string representation of a C.FormatSupport flag.

Parameters
@C.FormatSupport formatSupport: Int

A C.FormatSupport flag.

Returns
String!

A string representation of the flag.

getIntegerCodeForString

@UnstableApi
java-static fun getIntegerCodeForString(string: String!): Int

Returns the integer equal to the big-endian concatenation of the characters in string as bytes. The string must be no more than four characters long.

Parameters
string: String!

A string no more than four characters long.

getLocaleLanguageTag

@UnstableApi
java-static fun getLocaleLanguageTag(locale: Locale!): String!

Returns the language tag for a Locale.

For API levels ≥ 21, this tag is IETF BCP 47 compliant. Use normalizeLanguageCode to retrieve a normalized IETF BCP 47 language tag for all API levels if needed.

Parameters
locale: Locale!

A Locale.

Returns
String!

The language tag.

getMaxPendingFramesCountForMediaCodecDecoders

@UnstableApi
java-static fun getMaxPendingFramesCountForMediaCodecDecoders(context: Context!): Int

Returns the number of maximum pending output frames that are allowed on a MediaCodec decoder.

getMediaDurationForPlayoutDuration

@UnstableApi
java-static fun getMediaDurationForPlayoutDuration(playoutDuration: Long, speed: Float): Long

Returns the duration of media that will elapse in playoutDuration.

Parameters
playoutDuration: Long

The duration to scale.

speed: Float

The factor by which playback is sped up.

Returns
Long

The scaled duration, in the same units as playoutDuration.

getNowUnixTimeMs

@UnstableApi
java-static fun getNowUnixTimeMs(elapsedRealtimeEpochOffsetMs: Long): Long

Returns the current time in milliseconds since the epoch.

Parameters
elapsedRealtimeEpochOffsetMs: Long

The offset between elapsedRealtime and the time since the Unix epoch, or TIME_UNSET if unknown.

Returns
Long

The Unix time in milliseconds since the epoch.

getPcmEncoding

@UnstableApi
@C.PcmEncoding
java-static fun getPcmEncoding(bitDepth: Int): Int

Converts a sample bit depth to a corresponding PCM encoding constant.

Parameters
bitDepth: Int

The bit depth. Supported values are 8, 16, 24 and 32.

Returns
Int

The corresponding encoding. One of ENCODING_PCM_8BIT, ENCODING_PCM_16BIT, ENCODING_PCM_24BIT and ENCODING_PCM_32BIT. If the bit depth is unsupported then ENCODING_INVALID is returned.

getPcmFormat

@UnstableApi
java-static fun getPcmFormat(audioFormat: AudioProcessor.AudioFormat!): Format!

Gets a PCM Format based on the AudioProcessor.AudioFormat.

getPcmFormat

@UnstableApi
java-static fun getPcmFormat(@C.PcmEncoding pcmEncoding: Int, channels: Int, sampleRate: Int): Format!

Gets a PCM Format with the specified parameters.

Parameters
@C.PcmEncoding pcmEncoding: Int

The C.PcmEncoding.

channels: Int

The number of channels, or NO_VALUE if unknown.

sampleRate: Int

The sample rate in Hz, or NO_VALUE if unknown.

Returns
Format!

The PCM format.

getPcmFrameSize

@UnstableApi
java-static fun getPcmFrameSize(@C.PcmEncoding pcmEncoding: Int, channelCount: Int): Int

Returns the frame size for audio with channelCount channels in the specified encoding.

Parameters
@C.PcmEncoding pcmEncoding: Int

The encoding of the audio data.

channelCount: Int

The channel count.

Returns
Int

The size of one audio frame in bytes.

getPlayoutDurationForMediaDuration

@UnstableApi
java-static fun getPlayoutDurationForMediaDuration(mediaDuration: Long, speed: Float): Long

Returns the playout duration of mediaDuration of media.

Parameters
mediaDuration: Long

The duration to scale.

speed: Float

The factor by which playback is sped up.

Returns
Long

The scaled duration, in the same units as mediaDuration.

getRoleFlagStrings

@UnstableApi
java-static fun getRoleFlagStrings(@C.RoleFlags roleFlags: Int): (Mutable)List<String!>!

Returns a list of strings representing the C.RoleFlags values present in roleFlags.

getSelectionFlagStrings

@UnstableApi
java-static fun getSelectionFlagStrings(@C.SelectionFlags selectionFlags: Int): (Mutable)List<String!>!

Returns a list of strings representing the C.SelectionFlags values present in selectionFlags.

getStreamTypeForAudioUsage

@UnstableApi
@C.StreamType
java-static fun getStreamTypeForAudioUsage(@C.AudioUsage usage: Int): Int

Returns the C.StreamType corresponding to the specified C.AudioUsage.

getStringForTime

@UnstableApi
java-static fun getStringForTime(
    builder: StringBuilder!,
    formatter: Formatter!,
    timeMs: Long
): String!

Returns the specified millisecond time formatted as a string.

Parameters
builder: StringBuilder!

The builder that formatter will write to.

formatter: Formatter!

The formatter.

timeMs: Long

The time to format as a string, in milliseconds.

Returns
String!

The time formatted as a string.

getSystemLanguageCodes

@UnstableApi
java-static fun getSystemLanguageCodes(): Array<String!>!

Returns a non-empty array of normalized IETF BCP 47 language tags for the system languages ordered by preference.

getTrackTypeString

@UnstableApi
java-static fun getTrackTypeString(@C.TrackType trackType: Int): String!

Returns a string representation of a C.TrackType.

Parameters
@C.TrackType trackType: Int

A C.TrackType constant,

Returns
String!

A string representation of this constant.

getUserAgent

@UnstableApi
java-static fun getUserAgent(context: Context!, applicationName: String!): String!

Returns a user agent string based on the given application name and the library version.

Parameters
context: Context!

A valid context of the calling application.

applicationName: String!

String that will be prefix'ed to the generated user agent.

Returns
String!

A user agent string generated using the applicationName and the library version.

getUtf8Bytes

@UnstableApi
java-static fun getUtf8Bytes(value: String!): ByteArray<Byte>!

Returns a new byte array containing the code points of a String encoded using UTF-8.

Parameters
value: String!

The String whose bytes should be obtained.

Returns
ByteArray<Byte>!

The code points encoding using UTF-8.

gzip

@UnstableApi
java-static fun gzip(input: ByteArray!): ByteArray<Byte>!

Compresses input using gzip and returns the result in a newly allocated byte array.

handlePauseButtonAction

java-static fun handlePauseButtonAction(player: Player?): Boolean

Updates the player to handle an interaction with a pause button.

This method assumes the pause button is enabled if shouldShowPlayButton returns false.

Parameters
player: Player?

The Player. May be null.

Returns
Boolean

Whether a player method was triggered to handle this action.

handlePlayButtonAction

java-static fun handlePlayButtonAction(player: Player?): Boolean

Updates the player to handle an interaction with a play button.

This method assumes the play button is enabled if shouldShowPlayButton returns true.

Parameters
player: Player?

The Player. May be null.

Returns
Boolean

Whether a player method was triggered to handle this action.

handlePlayPauseButtonAction

java-static fun handlePlayPauseButtonAction(player: Player?): Boolean

Updates the player to handle an interaction with a play or pause button.

This method assumes that the UI element enables a play button if shouldShowPlayButton returns true and a pause button otherwise.

Parameters
player: Player?

The Player. May be null.

Returns
Boolean

Whether a player method was triggered to handle this action.

handlePlayPauseButtonAction

@UnstableApi
java-static fun handlePlayPauseButtonAction(player: Player?, playIfSuppressed: Boolean): Boolean

Updates the player to handle an interaction with a play or pause button.

This method assumes that the UI element enables a play button if shouldShowPlayButton returns true and a pause button otherwise.

Parameters
player: Player?

The Player. May be null.

playIfSuppressed: Boolean

Whether to trigger a play action if playback is suppressed.

Returns
Boolean

Whether a player method was triggered to handle this action.

inferContentType

@UnstableApi
@C.ContentType
java-static fun inferContentType(fileName: String!): Int

inferContentType

@C.ContentType
java-static fun inferContentType(uri: Uri!): Int

Makes a best guess to infer the ContentType from a Uri.

Parameters
uri: Uri!

The Uri.

Returns
Int

The content type.

inferContentType

@UnstableApi
@C.ContentType
java-static fun inferContentType(uri: Uri!, overrideExtension: String?): Int

inferContentTypeForExtension

@C.ContentType
java-static fun inferContentTypeForExtension(fileExtension: String!): Int

Makes a best guess to infer the ContentType from a file extension.

Parameters
fileExtension: String!

The extension of the file (excluding the '.').

Returns
Int

The content type.

inferContentTypeForUriAndMimeType

@C.ContentType
java-static fun inferContentTypeForUriAndMimeType(uri: Uri!, mimeType: String?): Int

Makes a best guess to infer the ContentType from a Uri and optional MIME type.

Parameters
uri: Uri!

The Uri.

mimeType: String?

If MIME type, or null.

Returns
Int

The content type.

inflate

@UnstableApi
java-static fun inflate(
    input: ParsableByteArray!,
    output: ParsableByteArray!,
    inflater: Inflater?
): Boolean

Uncompresses the data in input.

Parameters
input: ParsableByteArray!

Wraps the compressed input data.

output: ParsableByteArray!

Wraps an output buffer to be used to store the uncompressed data. If output.data isn't big enough to hold the uncompressed data, a new array is created. If true is returned then the output's position will be set to 0 and its limit will be set to the length of the uncompressed data.

inflater: Inflater?

If not null, used to uncompressed the input. Otherwise a new Inflater is created.

Returns
Boolean

Whether the input is uncompressed successfully.

intToStringMaxRadix

@UnstableApi
java-static fun intToStringMaxRadix(i: Int): String!

Returns a string representation of the integer using radix value MAX_RADIX.

Parameters
i: Int

An integer to be converted to String.

isAutomotive

@UnstableApi
java-static fun isAutomotive(context: Context!): Boolean

Returns whether the app is running on an automotive device.

Parameters
context: Context!

Any context.

Returns
Boolean

Whether the app is running on an automotive device.

isBitmapFactorySupportedMimeType

@UnstableApi
java-static fun isBitmapFactorySupportedMimeType(mimeType: String!): Boolean

Returns the image MIME types that can be decoded and loaded by that Media3 aims to support.

isEncodingHighResolutionPcm

@UnstableApi
java-static fun isEncodingHighResolutionPcm(@C.PcmEncoding encoding: Int): Boolean

Returns whether encoding is high resolution (> 16-bit) PCM.

Parameters
@C.PcmEncoding encoding: Int

The encoding of the audio data.

Returns
Boolean

Whether the encoding is high resolution PCM.

isEncodingLinearPcm

@UnstableApi
java-static fun isEncodingLinearPcm(@C.Encoding encoding: Int): Boolean

Returns whether encoding is one of the linear PCM encodings.

Parameters
@C.Encoding encoding: Int

The encoding of the audio data.

Returns
Boolean

Whether the encoding is one of the PCM encodings.

isFrameDropAllowedOnSurfaceInput

@UnstableApi
java-static fun isFrameDropAllowedOnSurfaceInput(context: Context!): Boolean

isLinebreak

@UnstableApi
java-static fun isLinebreak(c: Int): Boolean

Returns whether the given character is a carriage return ('\r') or a line feed ('\n').

Parameters
c: Int

The character.

Returns
Boolean

Whether the given character is a linebreak.

isLocalFileUri

@UnstableApi
java-static fun isLocalFileUri(uri: Uri!): Boolean

Returns true if the URI is a path to a local file or a reference to a local file.

Parameters
uri: Uri!

The uri to test.

isRunningOnEmulator

@UnstableApi
java-static fun isRunningOnEmulator(): Boolean

Returns true if the code path is currently running on an emulator.

isTv

@UnstableApi
java-static fun isTv(context: Context!): Boolean

Returns whether the app is running on a TV device.

Parameters
context: Context!

Any context.

Returns
Boolean

Whether the app is running on a TV device.

isWear

@UnstableApi
java-static fun isWear(context: Context!): Boolean

Returns whether the app is running on a Wear OS device.

Parameters
context: Context!

Any context.

Returns
Boolean

Whether the app is running on a Wear OS device.

linearSearch

@UnstableApi
java-static fun linearSearch(array: IntArray!, value: Int): Int

Returns the index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

Parameters
array: IntArray!

The array to search.

value: Int

The value to search for.

Returns
Int

The index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

linearSearch

@UnstableApi
java-static fun linearSearch(array: LongArray!, value: Long): Int

Returns the index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

Parameters
array: LongArray!

The array to search.

value: Long

The value to search for.

Returns
Int

The index of the first occurrence of value in array, or INDEX_UNSET if value is not contained in array.

loadAsset

@UnstableApi
java-static fun loadAsset(context: Context!, assetPath: String!): String!

Loads a file from the assets folder.

This should only be used for known-small files. Generally, loading assets should be done with AssetDataSource.

The file is assumed to be encoded in UTF-8.

Parameters
context: Context!

The Context.

assetPath: String!

The path to the file to load, from the assets folder.

Returns
String!

The content of the file to load.

Throws
java.io.IOException

If the file couldn't be read.

maxValue

@UnstableApi
@RequiresApi(value = 18)
java-static fun maxValue(sparseLongArray: SparseLongArray!): Long

Returns the maximum value in the given SparseLongArray.

Parameters
sparseLongArray: SparseLongArray!

The SparseLongArray.

Returns
Long

The maximum value.

Throws
java.util.NoSuchElementException

If the array is empty.

maybeRequestReadExternalStoragePermission

java-static fun maybeRequestReadExternalStoragePermission(
    activity: Activity!,
    mediaItems: Array<MediaItem!>!
): Boolean

maybeRequestReadExternalStoragePermission

java-static fun maybeRequestReadExternalStoragePermission(
    activity: Activity!,
    uris: Array<Uri!>!
): Boolean

maybeRequestReadStoragePermission

java-static fun maybeRequestReadStoragePermission(
    activity: Activity!,
    mediaItems: Array<MediaItem!>!
): Boolean

Checks whether it's necessary to request storage reading permissions for the specified media items, requesting the permissions if necessary.

Parameters
activity: Activity!

The host activity for checking and requesting the permission.

mediaItems: Array<MediaItem!>!

Media itemss that may require storage reading permissions to read.

Returns
Boolean

Whether a permission request was made.

minValue

@UnstableApi
@RequiresApi(value = 18)
java-static fun minValue(sparseLongArray: SparseLongArray!): Long

Returns the minimum value in the given SparseLongArray.

Parameters
sparseLongArray: SparseLongArray!

The SparseLongArray.

Returns
Long

The minimum value.

Throws
java.util.NoSuchElementException

If the array is empty.

moveItems

@UnstableApi
java-static fun <T : Any?> moveItems(
    items: (Mutable)List<T!>!,
    fromIndex: Int,
    toIndex: Int,
    newFromIndex: Int
): Unit

Moves the elements starting at fromIndex to newFromIndex.

Parameters
items: (Mutable)List<T!>!

The list of which to move elements.

fromIndex: Int

The index at which the items to move start.

toIndex: Int

The index up to which elements should be moved (exclusive).

newFromIndex: Int

The new from index.

msToUs

@UnstableApi
java-static fun msToUs(timeMs: Long): Long

Converts a time in milliseconds to the corresponding time in microseconds, preserving TIME_UNSET values and TIME_END_OF_SOURCE values.

Parameters
timeMs: Long

The time in milliseconds.

Returns
Long

The corresponding time in microseconds.

newSingleThreadExecutor

@UnstableApi
java-static fun newSingleThreadExecutor(threadName: String!): ExecutorService!

Instantiates a new single threaded executor whose thread has the specified name.

Parameters
threadName: String!

The name of the thread.

Returns
ExecutorService!

The executor.

newSingleThreadScheduledExecutor

@UnstableApi
java-static fun newSingleThreadScheduledExecutor(threadName: String!): ScheduledExecutorService!

Instantiates a new single threaded scheduled executor whose thread has the specified name.

Parameters
threadName: String!

The name of the thread.

Returns
ScheduledExecutorService!

The executor.

normalizeLanguageCode

@UnstableApi
@PolyNull
java-static fun normalizeLanguageCode(@PolyNull language: @PolyNull String!): @PolyNull String!

Returns a normalized IETF BCP 47 language tag for language.

Parameters
@PolyNull language: @PolyNull String!

A case-insensitive language code supported by forLanguageTag.

Returns
@PolyNull String!

The all-lowercase normalized code, or null if the input was null, or language.toLowerCase() if the language could not be normalized.

nullSafeArrayAppend

@UnstableApi
java-static fun <T> nullSafeArrayAppend(original: Array<T!>!, newElement: T!): Array<T!>!

Creates a new array containing original with newElement appended.

Parameters
original: Array<T!>!

The input array.

newElement: T!

The element to append.

Returns
Array<T!>!

The new array.

nullSafeArrayConcatenation

@UnstableApi
java-static fun <T> nullSafeArrayConcatenation(first: Array<T!>!, second: Array<T!>!): Array<T!>!

Creates a new array containing the concatenation of two non-null type arrays.

Parameters
first: Array<T!>!

The first array.

second: Array<T!>!

The second array.

Returns
Array<T!>!

The concatenated result.

nullSafeArrayCopy

@UnstableApi
java-static fun <T> nullSafeArrayCopy(input: Array<T!>!, length: Int): Array<T!>!

Copies and optionally truncates an array. Prevents null array elements created by copyOf by ensuring the new length does not exceed the current length.

Parameters
input: Array<T!>!

The input array.

length: Int

The output array length. Must be less or equal to the length of the input array.

Returns
Array<T!>!

The copied array.

nullSafeArrayCopyOfRange

@UnstableApi
java-static fun <T> nullSafeArrayCopyOfRange(input: Array<T!>!, from: Int, to: Int): Array<T!>!

Copies a subset of an array.

Parameters
input: Array<T!>!

The input array.

from: Int

The start the range to be copied, inclusive

to: Int

The end of the range to be copied, exclusive.

Returns
Array<T!>!

The copied array.

nullSafeListToArray

@UnstableApi
java-static fun <T> nullSafeListToArray(list: (Mutable)List<T!>!, array: Array<T!>!): Unit

Copies the contents of list into array.

list.size() must be the same as array.length to ensure the contents can be copied into array without leaving any nulls at the end.

Parameters
list: (Mutable)List<T!>!

The list to copy items from.

array: Array<T!>!

The array to copy items to.

parseXsDateTime

@UnstableApi
java-static fun parseXsDateTime(value: String!): Long

Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since the epoch.

Parameters
value: String!

The attribute value to decode.

Returns
Long

The parsed timestamp in milliseconds since the epoch.

Throws
androidx.media3.common.ParserException

if an error occurs parsing the dateTime attribute value.

parseXsDuration

@UnstableApi
java-static fun parseXsDuration(value: String!): Long

Parses an xs:duration attribute value, returning the parsed duration in milliseconds.

Parameters
value: String!

The attribute value to decode.

Returns
Long

The parsed duration in milliseconds.

postOrRun

@UnstableApi
java-static fun postOrRun(handler: Handler!, runnable: Runnable!): Boolean

Posts the Runnable if the calling thread differs with the Looper of the . Otherwise, runs the Runnable directly.

Parameters
handler: Handler!

The handler to which the Runnable will be posted.

runnable: Runnable!

The runnable to either post or run.

Returns
Boolean

true if the Runnable was successfully posted to the Handler or run. false otherwise.

postOrRunWithCompletion

@UnstableApi
java-static fun <T> postOrRunWithCompletion(
    handler: Handler!,
    runnable: Runnable!,
    successValue: T!
): ListenableFuture<T!>!

Posts the Runnable if the calling thread differs with the Looper of the . Otherwise, runs the Runnable directly. Also returns a for when the Runnable has run.

Parameters
<T>

The type of successValue.

handler: Handler!

The handler to which the Runnable will be posted.

runnable: Runnable!

The runnable to either post or run.

successValue: T!

The value to set in the ListenableFuture once the runnable completes.

Returns
ListenableFuture<T!>!

A ListenableFuture for when the Runnable has run.

readBoolean

@UnstableApi
java-static fun readBoolean(parcel: Parcel!): Boolean

Reads an integer from a Parcel and interprets it as a boolean, with 0 mapping to false and all other values mapping to true.

Parameters
parcel: Parcel!

The Parcel to read from.

Returns
Boolean

The read value.

recursiveDelete

@UnstableApi
java-static fun recursiveDelete(fileOrDirectory: File!): Unit

Recursively deletes a directory and its content.

registerReceiverNotExported

@UnstableApi
java-static fun registerReceiverNotExported(
    context: Context!,
    receiver: BroadcastReceiver?,
    filter: IntentFilter!
): Intent?

Registers a BroadcastReceiver that's not intended to receive broadcasts from other apps. This will be enforced by specifying RECEIVER_NOT_EXPORTED if SDK_INT is 33 or above.

Do not use this method if registering a receiver for a protected system broadcast.

Parameters
receiver: BroadcastReceiver?

The BroadcastReceiver to register. This value may be null.

context: Context!

The context on which registerReceiver will be called.

filter: IntentFilter!

Selects the Intent broadcasts to be received.

Returns
Intent?

The first sticky intent found that matches filter, or null if there are none.

removeRange

@UnstableApi
java-static fun <T> removeRange(list: (Mutable)List<T!>!, fromIndex: Int, toIndex: Int): Unit

Removes an indexed range from a List.

Does nothing if the provided range is valid and fromIndex == toIndex.

Parameters
list: (Mutable)List<T!>!

The List to remove the range from.

fromIndex: Int

The first index to be removed (inclusive).

toIndex: Int

The last index to be removed (exclusive).

Throws
java.lang.IllegalArgumentException

If fromIndex<0, toIndex> list.size(), or fromIndex>toIndex.

sampleCountToDurationUs

@UnstableApi
java-static fun sampleCountToDurationUs(sampleCount: Long, sampleRate: Int): Long

Returns the total duration (in microseconds) of sampleCount samples of equal duration at sampleRate.

If sampleRate is less than MICROS_PER_SECOND, the duration produced by this method can be reversed to the original sample count using durationUsToSampleCount.

Parameters
sampleCount: Long

The number of samples.

sampleRate: Int

The sample rate, in samples per second.

Returns
Long

The total duration, in microseconds, of sampleCount samples.

scaleLargeTimestamp

@UnstableApi
java-static fun scaleLargeTimestamp(timestamp: Long, multiplier: Long, divisor: Long): Long

Scales a large timestamp.

Equivalent to scaleLargeValue with FLOOR.

Parameters
timestamp: Long

The timestamp to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

Returns
Long

The scaled timestamp.

scaleLargeTimestamps

@UnstableApi
java-static fun scaleLargeTimestamps(
    timestamps: (Mutable)List<Long!>!,
    multiplier: Long,
    divisor: Long
): LongArray<Long>!

Applies scaleLargeTimestamp to a list of unscaled timestamps.

Parameters
timestamps: (Mutable)List<Long!>!

The timestamps to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

Returns
LongArray<Long>!

The scaled timestamps.

scaleLargeTimestampsInPlace

@UnstableApi
java-static fun scaleLargeTimestampsInPlace(
    timestamps: LongArray!,
    multiplier: Long,
    divisor: Long
): Unit

Applies scaleLargeTimestamp to an array of unscaled timestamps.

Parameters
timestamps: LongArray!

The timestamps to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

scaleLargeValue

@UnstableApi
java-static fun scaleLargeValue(
    value: Long,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
): Long

Scales a large value by a multiplier and a divisor.

The order of operations in this implementation is designed to minimize the probability of overflow. The implementation tries to stay in integer arithmetic as long as possible, but falls through to floating-point arithmetic if the values can't be combined without overflowing signed 64-bit longs.

If the mathematical result would overflow or underflow a 64-bit long, the result will be either MAX_VALUE or MIN_VALUE, respectively.

Parameters
value: Long

The value to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

roundingMode: RoundingMode!

The rounding mode to use if the result of the division is not an integer.

Returns
Long

The scaled value.

scaleLargeValues

@UnstableApi
java-static fun scaleLargeValues(
    values: (Mutable)List<Long!>!,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
): LongArray<Long>!

Applies scaleLargeValue to a list of unscaled values.

Parameters
values: (Mutable)List<Long!>!

The values to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

roundingMode: RoundingMode!

The rounding mode to use if the result of the division is not an integer.

Returns
LongArray<Long>!

The scaled values.

scaleLargeValuesInPlace

@UnstableApi
java-static fun scaleLargeValuesInPlace(
    values: LongArray!,
    multiplier: Long,
    divisor: Long,
    roundingMode: RoundingMode!
): Unit

Applies scaleLargeValue to an array of unscaled values.

Parameters
values: LongArray!

The values to scale.

multiplier: Long

The multiplier.

divisor: Long

The divisor.

roundingMode: RoundingMode!

The rounding mode to use if the result of the division is not an integer.

setForegroundServiceNotification

@UnstableApi
java-static fun setForegroundServiceNotification(
    service: Service!,
    notificationId: Int,
    notification: Notification!,
    foregroundServiceType: Int,
    foregroundServiceManifestType: String!
): Unit

Sets the notification required for a foreground service.

Parameters
service: Service!

The foreground Service.

notificationId: Int

The notification id.

notification: Notification!

The Notification.

foregroundServiceType: Int

The foreground service type defined in .

foregroundServiceManifestType: String!

The required foreground service type string for the <service> element in the manifest.

shouldShowPlayButton

@EnsuresNonNullIf(result = false, expression = "#1")
java-static fun shouldShowPlayButton(player: Player?): Boolean

Returns whether a play button should be presented on a UI element for playback control. If false, a pause button should be shown instead.

Use handlePlayPauseButtonAction, handlePlayButtonAction or handlePauseButtonAction to handle the interaction with the play or pause button UI element.

Parameters
player: Player?

The Player. May be null.

shouldShowPlayButton

@UnstableApi
@EnsuresNonNullIf(result = false, expression = "#1")
java-static fun shouldShowPlayButton(player: Player?, playIfSuppressed: Boolean): Boolean

Returns whether a play button should be presented on a UI element for playback control. If false, a pause button should be shown instead.

Use handlePlayPauseButtonAction, handlePlayButtonAction or handlePauseButtonAction to handle the interaction with the play or pause button UI element.

Parameters
player: Player?

The Player. May be null.

playIfSuppressed: Boolean

Whether to show a play button if playback is suppressed.

sneakyThrow

@UnstableApi
java-static fun sneakyThrow(t: Throwable!): Unit

A hacky method that always throws t even if t is a checked exception, and is not declared to be thrown.

split

@UnstableApi
java-static fun split(value: String!, regex: String!): Array<String!>!

Splits a string using value.split(regex, -1). Note: this is similar to split but empty matches at the end of the string will not be omitted from the returned array.

Parameters
value: String!

The string to split.

regex: String!

A delimiting regular expression.

Returns
Array<String!>!

The array of strings resulting from splitting the string.

splitAtFirst

@UnstableApi
java-static fun splitAtFirst(value: String!, regex: String!): Array<String!>!

Splits the string at the first occurrence of the delimiter regex. If the delimiter does not match, returns an array with one element which is the input string. If the delimiter does match, returns an array with the portion of the string before the delimiter and the rest of the string.

Parameters
value: String!

The string.

regex: String!

A delimiting regular expression.

Returns
Array<String!>!

The string split by the first occurrence of the delimiter.

splitCodecs

@UnstableApi
java-static fun splitCodecs(codecs: String?): Array<String!>!

Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.

Parameters
codecs: String?

A codec sequence string, as defined in RFC 6381.

Returns
Array<String!>!

The split codecs, or an array of length zero if the input was empty or null.

startForegroundService

@UnstableApi
java-static fun startForegroundService(context: Context!, intent: Intent!): ComponentName?

Calls startForegroundService if SDK_INT is 26 or higher, or startService otherwise.

Parameters
context: Context!

The context to call.

intent: Intent!

The intent to pass to the called method.

Returns
ComponentName?

The result of the called method.

subtractWithOverflowDefault

@UnstableApi
java-static fun subtractWithOverflowDefault(x: Long, y: Long, overflowResult: Long): Long

Returns the difference between two arguments, or a third argument if the result overflows.

Parameters
x: Long

The first value.

y: Long

The second value.

overflowResult: Long

The return value if x - y overflows.

Returns
Long

x - y, or overflowResult if the result overflows.

sum

@UnstableApi
java-static fun sum(summands: LongArray!): Long

Returns the sum of all summands of the given array.

Parameters
summands: LongArray!

The summands to calculate the sum from.

Returns
Long

The sum of all summands.

tableExists

@UnstableApi
java-static fun tableExists(database: SQLiteDatabase!, tableName: String!): Boolean

Returns whether the table exists in the database.

toByteArray

@UnstableApi
java-static fun toByteArray(inputStream: InputStream!): ByteArray<Byte>!

Converts the entirety of an InputStream to a byte array.

Parameters
inputStream: InputStream!

the InputStream to be read. The input stream is not closed by this method.

Returns
ByteArray<Byte>!

a byte array containing all of the inputStream's bytes.

Throws
java.io.IOException

if an error occurs reading from the stream.

toByteArray

@UnstableApi
java-static fun toByteArray(value: Float): ByteArray<Byte>!

Converts a float into an equivalent byte array.

toByteArray

@UnstableApi
java-static fun toByteArray(value: Int): ByteArray<Byte>!

Converts an integer into an equivalent byte array.

toByteArray

@UnstableApi
java-static fun toByteArray(values: IntArray!): ByteArray<Byte>!

Converts an array of integers into an equivalent byte array.

Each integer is converted into 4 sequential bytes.

toFloat

@UnstableApi
java-static fun toFloat(bytes: ByteArray!): Float

Converts a byte array into a float.

toHexString

@UnstableApi
java-static fun toHexString(bytes: ByteArray!): String!

Returns a string containing a lower-case hex representation of the bytes provided.

Parameters
bytes: ByteArray!

The byte data to convert to hex.

Returns
String!

A String containing the hex representation of bytes.

toInteger

@UnstableApi
java-static fun toInteger(bytes: ByteArray!): Int

Converts a byte array into an integer.

toLong

@UnstableApi
java-static fun toLong(mostSignificantBits: Int, leastSignificantBits: Int): Long

Returns the long that is composed of the bits of the 2 specified integers.

Parameters
mostSignificantBits: Int

The 32 most significant bits of the long to return.

leastSignificantBits: Int

The 32 least significant bits of the long to return.

Returns
Long

a long where its 32 most significant bits are mostSignificantBits bits and its 32 least significant bits are leastSignificantBits.

toUnsignedLong

@UnstableApi
java-static fun toUnsignedLong(x: Int): Long

Converts an integer to a long by unsigned conversion.

This method is equivalent to toUnsignedLong for API 26+.

transformFutureAsync

@UnstableApi
java-static fun <T, U> transformFutureAsync(
    future: ListenableFuture<U!>!,
    transformFunction: AsyncFunction<U!, T!>!
): ListenableFuture<T!>!

Asynchronously transforms the result of a ListenableFuture.

The transformation function is called using a direct executor.

The returned Future attempts to keep its cancellation state in sync with that of the input future and that of the future returned by the transform function. That is, if the returned Future is cancelled, it will attempt to cancel the other two, and if either of the other two is cancelled, the returned Future will also be cancelled. All forwarded cancellations will not attempt to interrupt.

Parameters
<T>

The result type of the input future.

<U>

The result type of the transformation function.

future: ListenableFuture<U!>!

The input ListenableFuture.

transformFunction: AsyncFunction<U!, T!>!

The function transforming the result of the input future.

Returns
ListenableFuture<T!>!

A ListenableFuture for the transformed result.

unescapeFileName

@UnstableApi
java-static fun unescapeFileName(fileName: String!): String?

Unescapes an escaped file or directory name back to its original value.

See escapeFileName for more information.

Parameters
fileName: String!

File name to be unescaped.

Returns
String?

The original value of the file name before it was escaped, or null if the escaped fileName seems invalid.

usToMs

@UnstableApi
java-static fun usToMs(timeUs: Long): Long

Converts a time in microseconds to the corresponding time in milliseconds, preserving TIME_UNSET and TIME_END_OF_SOURCE values.

Parameters
timeUs: Long

The time in microseconds.

Returns
Long

The corresponding time in milliseconds.

writeBoolean

@UnstableApi
java-static fun writeBoolean(parcel: Parcel!, value: Boolean): Unit

Writes a boolean to a Parcel. The boolean is written as an integer with value 1 (true) or 0 (false).

Parameters
parcel: Parcel!

The Parcel to write to.

value: Boolean

The value to write.