com.google.android.exoplayer2.util.Clock Java Examples

The following examples show how to use com.google.android.exoplayer2.util.Clock. 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: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in ExoPlayerFactory.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #2
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #3
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in {@link
 *     SimpleExoPlayer.Builder}.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
}
 
Example #4
Source File: ExoPlayerFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
 *     be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
 *     MediaSource} factories.
 */
@SuppressWarnings("deprecation")
@Deprecated
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector analyticsCollector,
    Looper looper) {
  return new SimpleExoPlayer(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollector,
      Clock.DEFAULT,
      looper);
}
 
Example #5
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 #6
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
 *     bandwidth meter should be directly passed to the player in {@link ExoPlayerFactory}.
 */
@Deprecated
public Factory(
    @Nullable BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseMs = minDurationForQualityIncreaseMs;
  this.maxDurationForQualityDecreaseMs = maxDurationForQualityDecreaseMs;
  this.minDurationToRetainAfterDiscardMs = minDurationToRetainAfterDiscardMs;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  trackBitrateEstimator = TrackBitrateEstimator.DEFAULT;
}
 
Example #7
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in {@link SimpleExoPlayer.Builder}.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #8
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param group The {@link TrackGroup}.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     empty. May be in any order.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth.
 */
public AdaptiveTrackSelection(TrackGroup group, int[] tracks,
    BandwidthMeter bandwidthMeter) {
  this(
      group,
      tracks,
      bandwidthMeter,
      /* reservedBandwidth= */ 0,
      DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
      DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
      DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
      DEFAULT_BANDWIDTH_FRACTION,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #9
Source File: CompositeTrackSelectorCreator.java    From no-player with Apache License 2.0 6 votes vote down vote up
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) {
    TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(
            bandwidthMeter,
            options.minDurationBeforeQualityIncreaseInMillis(),
            AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
            AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION,
            AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
            AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
            Clock.DEFAULT
    );
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
    DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters()
            .setMaxVideoBitrate(options.maxVideoBitrate())
            .build();
    trackSelector.setParameters(trackSelectorParameters);

    ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector);
    ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector);
    ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector);
    ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector);
    return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector);
}
 
Example #10
Source File: AdaptiveTrackSelection.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private AdaptiveTrackSelection(
    TrackGroup group,
    int[] tracks,
    BandwidthProvider bandwidthProvider,
    long minDurationForQualityIncreaseMs,
    long maxDurationForQualityDecreaseMs,
    long minDurationToRetainAfterDiscardMs,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  super(group, tracks);
  this.bandwidthProvider = bandwidthProvider;
  this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
  this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
  this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  playbackSpeed = 1f;
  reason = C.SELECTION_REASON_UNKNOWN;
  lastBufferEvaluationMs = C.TIME_UNSET;
}
 
Example #11
Source File: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollector A factory for creating the {@link AnalyticsCollector} that will
 *     collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
@SuppressWarnings("deprecation")
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector analyticsCollector,
    Clock clock,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      DrmSessionManager.getDummyDrmSessionManager(),
      bandwidthMeter,
      analyticsCollector,
      clock,
      looper);
}
 
Example #12
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
 *     be directly passed to the player in {@link ExoPlayerFactory}.
 */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(
    BandwidthMeter bandwidthMeter,
    int minDurationForQualityIncreaseMs,
    int maxDurationForQualityDecreaseMs,
    int minDurationToRetainAfterDiscardMs,
    float bandwidthFraction) {
  this(
      bandwidthMeter,
      minDurationForQualityIncreaseMs,
      maxDurationForQualityDecreaseMs,
      minDurationToRetainAfterDiscardMs,
      bandwidthFraction,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #13
Source File: ExoMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void initPlayer() {
    mInternalPlayer = new SimpleExoPlayer.Builder(
            mAppContext,
            mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory,
            mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector,
            mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl,
            DefaultBandwidthMeter.getSingletonInstance(mAppContext),
            Util.getLooper(),
            new AnalyticsCollector(Clock.DEFAULT),
            /* useLazyPreparation= */ true,
            Clock.DEFAULT)
            .build();
    setOptions();

    //播放器日志
    if (VideoViewManager.getConfig().mIsEnableLog && mTrackSelector instanceof MappingTrackSelector) {
        mInternalPlayer.addAnalyticsListener(new EventLogger((MappingTrackSelector) mTrackSelector, "ExoPlayer"));
    }

    mInternalPlayer.addListener(this);
    mInternalPlayer.addVideoListener(this);
}
 
Example #14
Source File: ExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a builder with the specified custom components.
 *
 * <p>Note that this constructor is only useful if you try to ensure that ExoPlayer's default
 * components can be removed by ProGuard or R8. For most components except renderers, there is
 * only a marginal benefit of doing that.
 *
 * @param renderers The {@link Renderer Renderers} to be used by the player.
 * @param trackSelector A {@link TrackSelector}.
 * @param loadControl A {@link LoadControl}.
 * @param bandwidthMeter A {@link BandwidthMeter}.
 * @param looper A {@link Looper} that must be used for all calls to the player.
 * @param analyticsCollector An {@link AnalyticsCollector}.
 * @param useLazyPreparation Whether media sources should be initialized lazily.
 * @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
 */
public Builder(
    Renderer[] renderers,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    Looper looper,
    AnalyticsCollector analyticsCollector,
    boolean useLazyPreparation,
    Clock clock) {
  Assertions.checkArgument(renderers.length > 0);
  this.renderers = renderers;
  this.trackSelector = trackSelector;
  this.loadControl = loadControl;
  this.bandwidthMeter = bandwidthMeter;
  this.looper = looper;
  this.analyticsCollector = analyticsCollector;
  this.useLazyPreparation = useLazyPreparation;
  this.clock = clock;
}
 
Example #15
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #16
Source File: SimpleExoPlayer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #17
Source File: ExoPlayerFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
 *     be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
 *     MediaSource} factories.
 */
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector(Clock.DEFAULT),
      Util.getLooper());
}
 
Example #18
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public ExoMediaPlayer(@NonNull Context context) {
    this.context = context;

    bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY);
    bufferRepeater.setRepeatListener(new BufferRepeatListener());

    mainHandler = new Handler();

    ComponentListener componentListener = new ComponentListener();
    RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener);
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager();
    rendererProvider.setDrmSessionManager(drmSessionManager);

    renderers = rendererProvider.generate();

    adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

    LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl();
    player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl);
    player.addListener(this);
    analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT);
    player.addListener(analyticsCollector);
    setupDamSessionManagerAnalytics(drmSessionManager);
}
 
Example #19
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 #20
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Creates an adaptive track selection factory with default parameters. */
public Factory() {
  this(
      DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
      DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
      DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
      DEFAULT_BANDWIDTH_FRACTION,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #21
Source File: AdaptiveTrackSelection.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/** Creates an adaptive track selection factory with default parameters. */
public Factory() {
  this(
      DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
      DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
      DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
      DEFAULT_BANDWIDTH_FRACTION,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #22
Source File: ExoPlayerFactory.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an {@link ExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderers The {@link Renderer}s that will be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
@SuppressWarnings("unused")
public static ExoPlayer newInstance(
    Context context,
    Renderer[] renderers,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    Looper looper) {
  return new ExoPlayerImpl(
      renderers, trackSelector, loadControl, bandwidthMeter, Clock.DEFAULT, looper);
}
 
Example #23
Source File: DefaultBandwidthMeter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** @deprecated Use {@link Builder} instead. */
@Deprecated
public DefaultBandwidthMeter(Handler eventHandler, EventListener eventListener) {
  this(DEFAULT_INITIAL_BITRATE_ESTIMATE, DEFAULT_SLIDING_WINDOW_MAX_WEIGHT, Clock.DEFAULT);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #24
Source File: DefaultBandwidthMeter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private DefaultBandwidthMeter(
    long initialBitrateEstimate,
    int maxWeight,
    Clock clock) {
  this.eventDispatcher = new EventDispatcher<>();
  this.slidingPercentile = new SlidingPercentile(maxWeight);
  this.clock = clock;
  bitrateEstimate = initialBitrateEstimate;
}
 
Example #25
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public ExoFFmpegPlayer(Context context) {

        super(context,
                new SimpleRendersFactory(context),
                new DefaultTrackSelector(),
                new DefaultLoadControl(),
                null,
                new DefaultBandwidthMeter.Builder().build(),
                new AnalyticsCollector.Factory(),
                Clock.DEFAULT,
                Util.getLooper());
    }
 
Example #26
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param group The {@link TrackGroup}.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     empty. May be in any order.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth.
 * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
 *     selected track to switch to one of higher quality.
 * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
 *     selected track to switch to one of lower quality.
 * @param minDurationToRetainAfterDiscardMs When switching to a track of significantly higher
 *     quality, the selection may indicate that media already buffered at the lower quality can be
 *     discarded to speed up the switch. This is the minimum duration of media that must be
 *     retained at the lower quality.
 * @param bandwidthFraction The fraction of the available bandwidth that the selection should
 *     consider available for use. Setting to a value less than 1 is recommended to account for
 *     inaccuracies in the bandwidth estimator.
 * @param bufferedFractionToLiveEdgeForQualityIncrease For live streaming, the fraction of the
 *     duration from current playback position to the live edge that has to be buffered before the
 *     selected track can be switched to one of higher quality. This parameter is only applied
 *     when the playback position is closer to the live edge than {@code
 *     minDurationForQualityIncreaseMs}, which would otherwise prevent switching to a higher
 *     quality from happening.
 * @param minTimeBetweenBufferReevaluationMs The track selection may periodically reevaluate its
 *     buffer and discard some chunks of lower quality to improve the playback quality if network
 *     condition has changed. This is the minimum duration between 2 consecutive buffer
 *     reevaluation calls.
 */
public AdaptiveTrackSelection(
    TrackGroup group,
    int[] tracks,
    BandwidthMeter bandwidthMeter,
    long minDurationForQualityIncreaseMs,
    long maxDurationForQualityDecreaseMs,
    long minDurationToRetainAfterDiscardMs,
    float bandwidthFraction,
    float bufferedFractionToLiveEdgeForQualityIncrease,
    long minTimeBetweenBufferReevaluationMs,
    Clock clock) {
  super(group, tracks);
  this.bandwidthMeter = bandwidthMeter;
  this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
  this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
  this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
  this.bandwidthFraction = bandwidthFraction;
  this.bufferedFractionToLiveEdgeForQualityIncrease =
      bufferedFractionToLiveEdgeForQualityIncrease;
  this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
  this.clock = clock;
  playbackSpeed = 1f;
  reason = C.SELECTION_REASON_INITIAL;
  lastBufferEvaluationMs = C.TIME_UNSET;
  @SuppressWarnings("nullness:method.invocation.invalid")
  int selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
  this.selectedIndex = selectedIndex;
}
 
Example #27
Source File: AdaptiveTrackSelection.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param group The {@link TrackGroup}.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     empty. May be in any order.
 * @param bandwidthMeter Provides an estimate of the currently available bandwidth.
 */
public AdaptiveTrackSelection(TrackGroup group, int[] tracks,
    BandwidthMeter bandwidthMeter) {
  this(
      group,
      tracks,
      bandwidthMeter,
      DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
      DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
      DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
      DEFAULT_BANDWIDTH_FRACTION,
      DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
      DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
      Clock.DEFAULT);
}
 
Example #28
Source File: BufferSizeAdaptationBuilder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private BufferSizeAdaptiveTrackSelection(
    TrackGroup trackGroup,
    int[] tracks,
    BandwidthMeter bandwidthMeter,
    int minBufferMs,
    int maxBufferMs,
    int hysteresisBufferMs,
    float startUpBandwidthFraction,
    int startUpMinBufferForQualityIncreaseMs,
    DynamicFormatFilter dynamicFormatFilter,
    Clock clock) {
  super(trackGroup, tracks);
  this.bandwidthMeter = bandwidthMeter;
  this.minBufferUs = C.msToUs(minBufferMs);
  this.maxBufferUs = C.msToUs(maxBufferMs);
  this.hysteresisBufferUs = C.msToUs(hysteresisBufferMs);
  this.startUpBandwidthFraction = startUpBandwidthFraction;
  this.startUpMinBufferForQualityIncreaseUs = C.msToUs(startUpMinBufferForQualityIncreaseMs);
  this.dynamicFormatFilter = dynamicFormatFilter;
  this.clock = clock;

  formatBitrates = new int[length];
  maxBitrate = getFormat(/* index= */ 0).bitrate;
  minBitrate = getFormat(/* index= */ length - 1).bitrate;
  selectionReason = C.SELECTION_REASON_UNKNOWN;
  playbackSpeed = 1.0f;

  // We use a log-linear function to map from bitrate to buffer size:
  // buffer = slope * ln(bitrate) + intercept,
  // with buffer(minBitrate) = minBuffer and buffer(maxBitrate) = maxBuffer - hysteresisBuffer.
  bitrateToBufferFunctionSlope =
      (maxBufferUs - hysteresisBufferUs - minBufferUs)
          / Math.log((double) maxBitrate / minBitrate);
  bitrateToBufferFunctionIntercept =
      minBufferUs - bitrateToBufferFunctionSlope * Math.log(minBitrate);
}
 
Example #29
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public ExoFFmpegPlayer(Context context, TrackSelector trackSelector) {

        super(context,
                new SimpleRendersFactory(context),
                trackSelector,
                new DefaultLoadControl(),
                null,
                new DefaultBandwidthMeter.Builder().build(),
                new AnalyticsCollector.Factory(),
                Clock.DEFAULT,
                Util.getLooper());
    }
 
Example #30
Source File: DefaultBandwidthMeter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** @deprecated Use {@link Builder} instead. */
@Deprecated
public DefaultBandwidthMeter(Handler eventHandler, EventListener eventListener, int maxWeight) {
  this(DEFAULT_INITIAL_BITRATE_ESTIMATE, maxWeight, Clock.DEFAULT);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}