Java Code Examples for com.google.android.exoplayer2.util.Util#getNetworkType()

The following examples show how to use com.google.android.exoplayer2.util.Util#getNetworkType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultBandwidthMeter.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private DefaultBandwidthMeter(
    @Nullable Context context,
    SparseArray<Long> initialBitrateEstimates,
    int maxWeight,
    Clock clock,
    boolean resetOnNetworkTypeChange) {
  this.context = context == null ? null : context.getApplicationContext();
  this.initialBitrateEstimates = initialBitrateEstimates;
  this.eventDispatcher = new EventDispatcher<>();
  this.slidingPercentile = new SlidingPercentile(maxWeight);
  this.clock = clock;
  // Set the initial network type and bitrate estimate
  networkType = context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context);
  bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  // Register to receive connectivity actions if possible.
  if (context != null && resetOnNetworkTypeChange) {
    ConnectivityActionReceiver connectivityActionReceiver =
        ConnectivityActionReceiver.getInstance(context);
    connectivityActionReceiver.register(/* bandwidthMeter= */ this);
  }
}
 
Example 2
Source File: DefaultBandwidthMeter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private DefaultBandwidthMeter(
    @Nullable Context context,
    SparseArray<Long> initialBitrateEstimates,
    int maxWeight,
    Clock clock,
    boolean resetOnNetworkTypeChange) {
  this.context = context == null ? null : context.getApplicationContext();
  this.initialBitrateEstimates = initialBitrateEstimates;
  this.eventDispatcher = new EventDispatcher<>();
  this.slidingPercentile = new SlidingPercentile(maxWeight);
  this.clock = clock;
  // Set the initial network type and bitrate estimate
  networkType = context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context);
  bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  // Register to receive connectivity actions if possible.
  if (context != null && resetOnNetworkTypeChange) {
    ConnectivityActionReceiver connectivityActionReceiver =
        ConnectivityActionReceiver.getInstance(context);
    connectivityActionReceiver.register(/* bandwidthMeter= */ this);
  }
}
 
Example 3
Source File: DefaultBandwidthMeter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private DefaultBandwidthMeter(
    @Nullable Context context,
    SparseArray<Long> initialBitrateEstimates,
    int maxWeight,
    Clock clock,
    boolean resetOnNetworkTypeChange) {
  this.context = context == null ? null : context.getApplicationContext();
  this.initialBitrateEstimates = initialBitrateEstimates;
  this.eventDispatcher = new EventDispatcher<>();
  this.slidingPercentile = new SlidingPercentile(maxWeight);
  this.clock = clock;
  // Set the initial network type and bitrate estimate
  networkType = context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context);
  bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  // Register to receive connectivity actions if possible.
  if (context != null && resetOnNetworkTypeChange) {
    ConnectivityActionReceiver connectivityActionReceiver =
        ConnectivityActionReceiver.getInstance(context);
    connectivityActionReceiver.register(/* bandwidthMeter= */ this);
  }
}
 
Example 4
Source File: DefaultBandwidthMeter.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private synchronized void onConnectivityAction() {
  int networkType =
      networkTypeOverrideSet
          ? networkTypeOverride
          : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context));
  if (this.networkType == networkType) {
    return;
  }

  this.networkType = networkType;
  if (networkType == C.NETWORK_TYPE_OFFLINE
      || networkType == C.NETWORK_TYPE_UNKNOWN
      || networkType == C.NETWORK_TYPE_OTHER) {
    // It's better not to reset the bandwidth meter for these network types.
    return;
  }

  // Reset the bitrate estimate and report it, along with any bytes transferred.
  this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  long nowMs = clock.elapsedRealtime();
  int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0;
  maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate);

  // Reset the remainder of the state.
  sampleStartTimeMs = nowMs;
  sampleBytesTransferred = 0;
  totalBytesTransferred = 0;
  totalElapsedTimeMs = 0;
  slidingPercentile.reset();
}
 
Example 5
Source File: DefaultBandwidthMeter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void onConnectivityAction() {
  int networkType =
      networkTypeOverrideSet
          ? networkTypeOverride
          : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context));
  if (this.networkType == networkType) {
    return;
  }

  this.networkType = networkType;
  if (networkType == C.NETWORK_TYPE_OFFLINE
      || networkType == C.NETWORK_TYPE_UNKNOWN
      || networkType == C.NETWORK_TYPE_OTHER) {
    // It's better not to reset the bandwidth meter for these network types.
    return;
  }

  // Reset the bitrate estimate and report it, along with any bytes transferred.
  this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  long nowMs = clock.elapsedRealtime();
  int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0;
  maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate);

  // Reset the remainder of the state.
  sampleStartTimeMs = nowMs;
  sampleBytesTransferred = 0;
  totalBytesTransferred = 0;
  totalElapsedTimeMs = 0;
  slidingPercentile.reset();
}
 
Example 6
Source File: DefaultBandwidthMeter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void onConnectivityAction() {
  int networkType =
      networkTypeOverrideSet
          ? networkTypeOverride
          : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context));
  if (this.networkType == networkType) {
    return;
  }

  this.networkType = networkType;
  if (networkType == C.NETWORK_TYPE_OFFLINE
      || networkType == C.NETWORK_TYPE_UNKNOWN
      || networkType == C.NETWORK_TYPE_OTHER) {
    // It's better not to reset the bandwidth meter for these network types.
    return;
  }

  // Reset the bitrate estimate and report it, along with any bytes transferred.
  this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType);
  long nowMs = clock.elapsedRealtime();
  int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0;
  maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate);

  // Reset the remainder of the state.
  sampleStartTimeMs = nowMs;
  sampleBytesTransferred = 0;
  totalBytesTransferred = 0;
  totalElapsedTimeMs = 0;
  slidingPercentile.reset();
}