DefaultBandwidthMeter


@UnstableApi
class DefaultBandwidthMeter : BandwidthMeter, TransferListener


Estimates bandwidth by listening to data transfers.

The bandwidth estimate is calculated using a SlidingPercentile and is updated each time a transfer ends. The initial estimate is based on the current operator's network country code or the locale of the user, as well as the network connection type. This can be configured in the Builder.

Summary

Nested types

Builder for a bandwidth meter.

Constants

const Long

Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.

const ImmutableList<Long!>!

Default initial 2G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 3G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 4G bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 5G-NSA bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial 5G-SA bitrate estimates in bits per second.

const ImmutableList<Long!>!

Default initial Wifi bitrate estimate in bits per second.

const Int

Default maximum weight for the sliding window.

Public functions

Unit
addEventListener(
    eventHandler: Handler!,
    eventListener: BandwidthMeter.EventListener!
)

Adds an EventListener.

synchronized java-static DefaultBandwidthMeter!

Returns a singleton instance of a DefaultBandwidthMeter with default configuration.

TransferListener!

Returns the TransferListener that this instance uses to gather bandwidth information from data transfers.

synchronized Unit
onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
)

Called incrementally during a transfer.

synchronized Unit
onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer ends.

Unit
onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
)

Called when a transfer is being initialized.

synchronized Unit
onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean)

Called when a transfer starts.

Unit

Removes an EventListener.

synchronized Unit

Overrides the network type.

Public properties

Long
@GuardedBy(value = "this")
bitrateEstimate

Inherited functions

From androidx.media3.exoplayer.upstream.BandwidthMeter
Long

Returns the estimated time to first byte, in microseconds, or TIME_UNSET if no estimate is available.

Constants

DEFAULT_INITIAL_BITRATE_ESTIMATE

const val DEFAULT_INITIAL_BITRATE_ESTIMATE = 1000000: Long

Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_2G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_2GImmutableList<Long!>!

Default initial 2G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_3G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_3GImmutableList<Long!>!

Default initial 3G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_4G

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_4GImmutableList<Long!>!

Default initial 4G bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSAImmutableList<Long!>!

Default initial 5G-NSA bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SAImmutableList<Long!>!

Default initial 5G-SA bitrate estimates in bits per second.

DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI

const val DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFIImmutableList<Long!>!

Default initial Wifi bitrate estimate in bits per second.

DEFAULT_SLIDING_WINDOW_MAX_WEIGHT

const val DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000: Int

Default maximum weight for the sliding window.

Public functions

addEventListener

fun addEventListener(
    eventHandler: Handler!,
    eventListener: BandwidthMeter.EventListener!
): Unit

Adds an EventListener.

Parameters
eventHandler: Handler!

A handler for events.

eventListener: BandwidthMeter.EventListener!

A listener of events.

getSingletonInstance

synchronized java-static fun getSingletonInstance(context: Context!): DefaultBandwidthMeter!

Returns a singleton instance of a DefaultBandwidthMeter with default configuration.

Parameters
context: Context!

A Context.

Returns
DefaultBandwidthMeter!

The singleton instance.

getTransferListener

fun getTransferListener(): TransferListener!

Returns the TransferListener that this instance uses to gather bandwidth information from data transfers. May be null if the implementation does not listen to data transfers.

onBytesTransferred

synchronized fun onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
): Unit

Called incrementally during a transfer.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

bytesTransferred: Int

The number of bytes transferred since the previous call to this method.

onTransferEnd

synchronized fun onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer ends.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferInitializing

fun onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
): Unit

Called when a transfer is being initialized.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data for which the transfer is initialized.

isNetwork: Boolean

Whether the data is transferred through a network.

onTransferStart

synchronized fun onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit

Called when a transfer starts.

Parameters
source: DataSource!

The source performing the transfer.

dataSpec: DataSpec!

Describes the data being transferred.

isNetwork: Boolean

Whether the data is transferred through a network.

removeEventListener

fun removeEventListener(eventListener: BandwidthMeter.EventListener!): Unit

Removes an EventListener.

Parameters
eventListener: BandwidthMeter.EventListener!

The listener to be removed.

setNetworkTypeOverride

synchronized fun setNetworkTypeOverride(@C.NetworkType networkType: Int): Unit

Overrides the network type. Handled in the same way as if the meter had detected a change from the current network type to the specified network type internally.

Applications should not normally call this method. It is intended for testing purposes.

Parameters
@C.NetworkType networkType: Int

The overriding network type.

Public properties

bitrateEstimate

@GuardedBy(value = "this")
val bitrateEstimateLong