Java Code Examples for com.google.android.exoplayer2.upstream.DataSource#addTransferListener()

The following examples show how to use com.google.android.exoplayer2.upstream.DataSource#addTransferListener() . 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: SingleSampleMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public boolean continueLoading(long positionUs) {
  if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
    return false;
  }
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  long elapsedRealtimeMs =
      loader.startLoading(
          new SourceLoadable(dataSpec, dataSource),
          /* callback= */ this,
          loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA));
  eventDispatcher.loadStarted(
      dataSpec,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      format,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ 0,
      durationUs,
      elapsedRealtimeMs);
  return true;
}
 
Example 2
Source File: SingleSampleMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean continueLoading(long positionUs) {
  if (loadingFinished || loader.isLoading()) {
    return false;
  }
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  long elapsedRealtimeMs =
      loader.startLoading(
          new SourceLoadable(dataSpec, dataSource), /* callback= */ this, minLoadableRetryCount);
  eventDispatcher.loadStarted(
      dataSpec,
      dataSpec.uri,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      format,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ 0,
      durationUs,
      elapsedRealtimeMs);
  return true;
}
 
Example 3
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ExtractorMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      minLoadableRetryCount,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example 4
Source File: SingleSampleMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean continueLoading(long positionUs) {
  if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
    return false;
  }
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  long elapsedRealtimeMs =
      loader.startLoading(
          new SourceLoadable(dataSpec, dataSource),
          /* callback= */ this,
          loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA));
  eventDispatcher.loadStarted(
      dataSpec,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      format,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ 0,
      durationUs,
      elapsedRealtimeMs);
  return true;
}
 
Example 5
Source File: ProgressiveMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ProgressiveMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      loadableLoadErrorHandlingPolicy,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example 6
Source File: SingleSampleMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean continueLoading(long positionUs) {
  if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
    return false;
  }
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  long elapsedRealtimeMs =
      loader.startLoading(
          new SourceLoadable(dataSpec, dataSource),
          /* callback= */ this,
          loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA));
  eventDispatcher.loadStarted(
      dataSpec,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      format,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ 0,
      durationUs,
      elapsedRealtimeMs);
  return true;
}
 
Example 7
Source File: ProgressiveMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ProgressiveMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      loadableLoadErrorHandlingPolicy,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example 8
Source File: ProgressiveMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ProgressiveMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      drmSessionManager,
      loadableLoadErrorHandlingPolicy,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example 9
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DashChunkSource createDashChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest,
    int periodIndex,
    int[] adaptationSetIndices,
    TrackSelection trackSelection,
    int trackType,
    long elapsedRealtimeOffsetMs,
    boolean enableEventMessageTrack,
    boolean enableCea608Track,
    @Nullable PlayerTrackEmsgHandler playerEmsgHandler,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultDashChunkSource(
      manifestLoaderErrorThrower,
      manifest,
      periodIndex,
      adaptationSetIndices,
      trackSelection,
      trackType,
      dataSource,
      elapsedRealtimeOffsetMs,
      maxSegmentsPerLoad,
      enableEventMessageTrack,
      enableCea608Track,
      playerEmsgHandler);
}
 
Example 10
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DashChunkSource createDashChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest,
    int periodIndex,
    int[] adaptationSetIndices,
    TrackSelection trackSelection,
    int trackType,
    long elapsedRealtimeOffsetMs,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    @Nullable PlayerTrackEmsgHandler playerEmsgHandler,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultDashChunkSource(
      manifestLoaderErrorThrower,
      manifest,
      periodIndex,
      adaptationSetIndices,
      trackSelection,
      trackType,
      dataSource,
      elapsedRealtimeOffsetMs,
      maxSegmentsPerLoad,
      enableEventMessageTrack,
      closedCaptionFormats,
      playerEmsgHandler);
}
 
Example 11
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DashChunkSource createDashChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest,
    int periodIndex,
    int[] adaptationSetIndices,
    TrackSelection trackSelection,
    int trackType,
    long elapsedRealtimeOffsetMs,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    @Nullable PlayerTrackEmsgHandler playerEmsgHandler,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultDashChunkSource(
      manifestLoaderErrorThrower,
      manifest,
      periodIndex,
      adaptationSetIndices,
      trackSelection,
      trackType,
      dataSource,
      elapsedRealtimeOffsetMs,
      maxSegmentsPerLoad,
      enableEventMessageTrack,
      closedCaptionFormats,
      playerEmsgHandler);
}
 
Example 12
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}
 
Example 13
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}
 
Example 14
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DashChunkSource createDashChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest,
    int periodIndex,
    int[] adaptationSetIndices,
    TrackSelection trackSelection,
    int trackType,
    long elapsedRealtimeOffsetMs,
    boolean enableEventMessageTrack,
    boolean enableCea608Track,
    @Nullable PlayerTrackEmsgHandler playerEmsgHandler,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultDashChunkSource(
      manifestLoaderErrorThrower,
      manifest,
      periodIndex,
      adaptationSetIndices,
      trackSelection,
      trackType,
      dataSource,
      elapsedRealtimeOffsetMs,
      maxSegmentsPerLoad,
      enableEventMessageTrack,
      enableCea608Track,
      playerEmsgHandler);
}
 
Example 15
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(
      manifestLoaderErrorThrower, manifest, elementIndex, trackSelection, dataSource);
}
 
Example 16
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(
      manifestLoaderErrorThrower, manifest, elementIndex, trackSelection, dataSource);
}
 
Example 17
Source File: ExtendedDefaultDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void addListenersToDataSource(DataSource dataSource) {
    for (int i = 0; i < transferListeners.size(); i++) {
        dataSource.addTransferListener(transferListeners.get(i));
    }
}
 
Example 18
Source File: ExtendedDefaultDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void maybeAddListenerToDataSource(
        @Nullable DataSource dataSource, TransferListener listener) {
    if (dataSource != null) {
        dataSource.addTransferListener(listener);
    }
}
 
Example 19
Source File: ExtendedDefaultDataSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void addListenersToDataSource(DataSource dataSource) {
    for (int i = 0; i < transferListeners.size(); i++) {
        dataSource.addTransferListener(transferListeners.get(i));
    }
}
 
Example 20
Source File: ExtendedDefaultDataSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void maybeAddListenerToDataSource(
        @Nullable DataSource dataSource, TransferListener listener) {
    if (dataSource != null) {
        dataSource.addTransferListener(listener);
    }
}