Package com.brightcove.player.network
Class PlayerBandwidthMeter
- java.lang.Object
-
- com.brightcove.player.network.PlayerBandwidthMeter
-
- All Implemented Interfaces:
com.google.android.exoplayer2.upstream.BandwidthMeter
,com.google.android.exoplayer2.upstream.TransferListener
public class PlayerBandwidthMeter extends java.lang.Object implements com.google.android.exoplayer2.upstream.BandwidthMeter, com.google.android.exoplayer2.upstream.TransferListener
Provides an implementation ofBandwidthMeter
that tracks the total number of bytes transferred. By default all work will be delegated toDefaultBandwidthMeter
. The caller may override the delegate to another instance any time.
-
-
Field Summary
Fields Modifier and Type Field Description long
NO_ESTIMATE
Indicates no bandwidth estimate is available.
-
Constructor Summary
Constructors Constructor Description PlayerBandwidthMeter()
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.PlayerBandwidthMeter(android.content.Context context, android.os.Handler eventHandler, com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.PlayerBandwidthMeter(android.os.Handler eventHandler, com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.PlayerBandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter bandwidthMeter)
Constructs a new instance of the bandwidth meter that will use given bandwidth meter to delegate the work.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(android.os.Handler eventHandler, com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
long
getBitrateEstimate()
com.google.android.exoplayer2.upstream.BandwidthMeter
getDelegate()
Gets reference to actual bandwidth meter that is currently being delegated to handle bitrate estimate calculations.long
getTotalBytesTransferred()
Gets the total number of bytes transferred so far.com.google.android.exoplayer2.upstream.TransferListener
getTransferListener()
void
onBytesTransferred(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork, int bytesTransferred)
void
onTransferEnd(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
void
onTransferInitializing(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
void
onTransferStart(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
void
removeEventListener(com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
PlayerBandwidthMeter
resetTotalBytesTransferred()
Resets the counter for total number of bytes transferred.void
setDelegate(com.google.android.exoplayer2.upstream.BandwidthMeter bandwidthMeter)
Sets reference to actual bandwidth meter that must be used to handle bitrate estimate calculations.
-
-
-
Constructor Detail
-
PlayerBandwidthMeter
public PlayerBandwidthMeter()
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.
-
PlayerBandwidthMeter
public PlayerBandwidthMeter(@Nullable android.os.Handler eventHandler, @Nullable com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.- Parameters:
eventHandler
- reference to the event handler, if any.eventListener
- reference to the event listener, if any.
-
PlayerBandwidthMeter
public PlayerBandwidthMeter(@Nullable android.content.Context context, @Nullable android.os.Handler eventHandler, @Nullable com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
Constructs a new instance of the bandwidth meter that will useDefaultBandwidthMeter
internally to delegate the work.- Parameters:
eventHandler
- reference to the event handler, if any.eventListener
- reference to the event listener, if any.
-
PlayerBandwidthMeter
public PlayerBandwidthMeter(@Nullable com.google.android.exoplayer2.upstream.BandwidthMeter bandwidthMeter)
Constructs a new instance of the bandwidth meter that will use given bandwidth meter to delegate the work.- Parameters:
bandwidthMeter
- reference to the bandwidth meter to be used as delegate.
-
-
Method Detail
-
getBitrateEstimate
public long getBitrateEstimate()
- Specified by:
getBitrateEstimate
in interfacecom.google.android.exoplayer2.upstream.BandwidthMeter
-
getTransferListener
@Nullable public com.google.android.exoplayer2.upstream.TransferListener getTransferListener()
- Specified by:
getTransferListener
in interfacecom.google.android.exoplayer2.upstream.BandwidthMeter
-
addEventListener
public void addEventListener(android.os.Handler eventHandler, com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
- Specified by:
addEventListener
in interfacecom.google.android.exoplayer2.upstream.BandwidthMeter
-
removeEventListener
public void removeEventListener(com.google.android.exoplayer2.upstream.BandwidthMeter.EventListener eventListener)
- Specified by:
removeEventListener
in interfacecom.google.android.exoplayer2.upstream.BandwidthMeter
-
getDelegate
@Nullable public com.google.android.exoplayer2.upstream.BandwidthMeter getDelegate()
Gets reference to actual bandwidth meter that is currently being delegated to handle bitrate estimate calculations.- Returns:
- reference to a bandwidth meter, if available
-
setDelegate
public void setDelegate(@Nullable com.google.android.exoplayer2.upstream.BandwidthMeter bandwidthMeter)
Sets reference to actual bandwidth meter that must be used to handle bitrate estimate calculations.
-
onTransferInitializing
public void onTransferInitializing(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
- Specified by:
onTransferInitializing
in interfacecom.google.android.exoplayer2.upstream.TransferListener
-
onTransferStart
public void onTransferStart(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
- Specified by:
onTransferStart
in interfacecom.google.android.exoplayer2.upstream.TransferListener
-
onBytesTransferred
public void onBytesTransferred(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork, int bytesTransferred)
- Specified by:
onBytesTransferred
in interfacecom.google.android.exoplayer2.upstream.TransferListener
-
onTransferEnd
public void onTransferEnd(com.google.android.exoplayer2.upstream.DataSource source, com.google.android.exoplayer2.upstream.DataSpec dataSpec, boolean isNetwork)
- Specified by:
onTransferEnd
in interfacecom.google.android.exoplayer2.upstream.TransferListener
-
getTotalBytesTransferred
public long getTotalBytesTransferred()
Gets the total number of bytes transferred so far.- Returns:
- the total number of bytes transferred so far.
-
resetTotalBytesTransferred
public PlayerBandwidthMeter resetTotalBytesTransferred()
Resets the counter for total number of bytes transferred.- Returns:
- reference to the bandwidth meter.
-
-