Java Code Examples for com.google.android.exoplayer2.C#TIME_END_OF_SOURCE

The following examples show how to use com.google.android.exoplayer2.C#TIME_END_OF_SOURCE . 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: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  if (loadingFinished) {
    return C.TIME_END_OF_SOURCE;
  } else if (isPendingReset()) {
    return pendingResetPositionUs;
  } else {
    long bufferedPositionUs = lastSeekPositionUs;
    HlsMediaChunk lastMediaChunk = getLastMediaChunk();
    HlsMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk
        : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null;
    if (lastCompletedMediaChunk != null) {
      bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs);
    }
    if (sampleQueuesBuilt) {
      for (SampleQueue sampleQueue : sampleQueues) {
        bufferedPositionUs =
            Math.max(bufferedPositionUs, sampleQueue.getLargestQueuedTimestampUs());
      }
    }
    return bufferedPositionUs;
  }
}
 
Example 2
Source File: ExtractorMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  if (loadingFinished) {
    return C.TIME_END_OF_SOURCE;
  } else if (isPendingReset()) {
    return pendingResetPositionUs;
  }
  long largestQueuedTimestampUs;
  if (haveAudioVideoTracks) {
    // Ignore non-AV tracks, which may be sparse or poorly interleaved.
    largestQueuedTimestampUs = Long.MAX_VALUE;
    int trackCount = sampleQueues.length;
    for (int i = 0; i < trackCount; i++) {
      if (trackIsAudioVideoFlags[i]) {
        largestQueuedTimestampUs = Math.min(largestQueuedTimestampUs,
            sampleQueues[i].getLargestQueuedTimestampUs());
      }
    }
  } else {
    largestQueuedTimestampUs = getLargestQueuedTimestampUs();
  }
  return largestQueuedTimestampUs == Long.MIN_VALUE ? lastSeekPositionUs
      : largestQueuedTimestampUs;
}
 
Example 3
Source File: AdPlaybackState.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index of the next ad group after {@code positionUs} that has ads remaining to be
 * played. Returns {@link C#INDEX_UNSET} if there is no such ad group.
 *
 * @param positionUs The position after which to find an ad group, in microseconds, or {@link
 *     C#TIME_END_OF_SOURCE} for the end of the stream (in which case there can be no ad group
 *     after the position).
 * @param periodDurationUs The duration of the containing period in microseconds, or {@link
 *     C#TIME_UNSET} if not known.
 * @return The index of the ad group, or {@link C#INDEX_UNSET}.
 */
public int getAdGroupIndexAfterPositionUs(long positionUs, long periodDurationUs) {
  if (positionUs == C.TIME_END_OF_SOURCE
      || (periodDurationUs != C.TIME_UNSET && positionUs >= periodDurationUs)) {
    return C.INDEX_UNSET;
  }
  // Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
  // In practice we expect there to be few ad groups so the search shouldn't be expensive.
  int index = 0;
  while (index < adGroupTimesUs.length
      && adGroupTimesUs[index] != C.TIME_END_OF_SOURCE
      && (positionUs >= adGroupTimesUs[index] || !adGroups[index].hasUnplayedAds())) {
    index++;
  }
  return index < adGroupTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 4
Source File: ChunkSampleStream.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Returns an estimate of the position up to which data is buffered.
 *
 * @return An estimate of the absolute position in microseconds up to which data is buffered, or
 *     {@link C#TIME_END_OF_SOURCE} if the track is fully buffered.
 */
public long getBufferedPositionUs() {
  if (loadingFinished) {
    return C.TIME_END_OF_SOURCE;
  } else if (isPendingReset()) {
    return pendingResetPositionUs;
  } else {
    long bufferedPositionUs = lastSeekPositionUs;
    BaseMediaChunk lastMediaChunk = mediaChunks.getLast();
    BaseMediaChunk lastCompletedMediaChunk = lastMediaChunk.isLoadCompleted() ? lastMediaChunk
        : mediaChunks.size() > 1 ? mediaChunks.get(mediaChunks.size() - 2) : null;
    if (lastCompletedMediaChunk != null) {
      bufferedPositionUs = Math.max(bufferedPositionUs, lastCompletedMediaChunk.endTimeUs);
    }
    return Math.max(bufferedPositionUs, primarySampleQueue.getLargestQueuedTimestampUs());
  }
}
 
Example 5
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private boolean isPositionBeforeAdGroup(long positionUs, int adGroupIndex) {
  if (positionUs == C.TIME_END_OF_SOURCE) {
    // The end of the content is at (but not before) any postroll ad, and after any other ads.
    return false;
  }
  long adGroupPositionUs = adGroupTimesUs[adGroupIndex];
  if (adGroupPositionUs == C.TIME_END_OF_SOURCE) {
    return contentDurationUs == C.TIME_UNSET || positionUs < contentDurationUs;
  } else {
    return positionUs < adGroupPositionUs;
  }
}
 
Example 6
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getNextLoadPositionUs() {
  if (isPendingReset()) {
    return pendingResetPositionUs;
  } else {
    return loadingFinished ? C.TIME_END_OF_SOURCE : getLastMediaChunk().endTimeUs;
  }
}
 
Example 7
Source File: AdPlaybackState.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the index of the ad group at or before {@code positionUs}, if that ad group is
 * unplayed. Returns {@link C#INDEX_UNSET} if the ad group at or before {@code positionUs} has no
 * ads remaining to be played, or if there is no such ad group.
 *
 * @param positionUs The position at or before which to find an ad group, in microseconds.
 * @return The index of the ad group, or {@link C#INDEX_UNSET}.
 */
public int getAdGroupIndexForPositionUs(long positionUs) {
  // Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
  // In practice we expect there to be few ad groups so the search shouldn't be expensive.
  int index = adGroupTimesUs.length - 1;
  while (index >= 0
      && (adGroupTimesUs[index] == C.TIME_END_OF_SOURCE || adGroupTimesUs[index] > positionUs)) {
    index--;
  }
  return index >= 0 && adGroups[index].hasUnplayedAds() ? index : C.INDEX_UNSET;
}
 
Example 8
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected long getMediaTimeForChildMediaTime(Void id, long mediaTimeMs) {
  if (mediaTimeMs == C.TIME_UNSET) {
    return C.TIME_UNSET;
  }
  long startMs = C.usToMs(startUs);
  long clippedTimeMs = Math.max(0, mediaTimeMs - startMs);
  if (endUs != C.TIME_END_OF_SOURCE) {
    clippedTimeMs = Math.min(C.usToMs(endUs) - startMs, clippedTimeMs);
  }
  return clippedTimeMs;
}
 
Example 9
Source File: AdPlaybackState.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the index of the next ad group after {@code positionUs} that has ads remaining to be
 * played. Returns {@link C#INDEX_UNSET} if there is no such ad group.
 *
 * @param positionUs The position after which to find an ad group, in microseconds.
 * @return The index of the ad group, or {@link C#INDEX_UNSET}.
 */
public int getAdGroupIndexAfterPositionUs(long positionUs) {
  // Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
  // In practice we expect there to be few ad groups so the search shouldn't be expensive.
  int index = 0;
  while (index < adGroupTimesUs.length
      && adGroupTimesUs[index] != C.TIME_END_OF_SOURCE
      && (positionUs >= adGroupTimesUs[index] || !adGroups[index].hasUnplayedAds())) {
    index++;
  }
  return index < adGroupTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 10
Source File: AdPlaybackState.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private boolean isPositionBeforeAdGroup(long positionUs, int adGroupIndex) {
  if (positionUs == C.TIME_END_OF_SOURCE) {
    // The end of the content is at (but not before) any postroll ad, and after any other ads.
    return false;
  }
  long adGroupPositionUs = adGroupTimesUs[adGroupIndex];
  if (adGroupPositionUs == C.TIME_END_OF_SOURCE) {
    return contentDurationUs == C.TIME_UNSET || positionUs < contentDurationUs;
  } else {
    return positionUs < adGroupPositionUs;
  }
}
 
Example 11
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getNextLoadPositionUs() {
  if (isPendingReset()) {
    return pendingResetPositionUs;
  } else {
    return loadingFinished ? C.TIME_END_OF_SOURCE : getLastMediaChunk().endTimeUs;
  }
}
 
Example 12
Source File: ClippingMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long getNextLoadPositionUs() {
  long nextLoadPositionUs = mediaPeriod.getNextLoadPositionUs();
  if (nextLoadPositionUs == C.TIME_END_OF_SOURCE
      || (endUs != C.TIME_END_OF_SOURCE && nextLoadPositionUs >= endUs)) {
    return C.TIME_END_OF_SOURCE;
  }
  return nextLoadPositionUs;
}
 
Example 13
Source File: HlsMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  long bufferedPositionUs = Long.MAX_VALUE;
  for (HlsSampleStreamWrapper sampleStreamWrapper : enabledSampleStreamWrappers) {
    long rendererBufferedPositionUs = sampleStreamWrapper.getBufferedPositionUs();
    if (rendererBufferedPositionUs != C.TIME_END_OF_SOURCE) {
      bufferedPositionUs = Math.min(bufferedPositionUs, rendererBufferedPositionUs);
    }
  }
  return bufferedPositionUs == Long.MAX_VALUE ? C.TIME_END_OF_SOURCE : bufferedPositionUs;
}
 
Example 14
Source File: ClippingMediaSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected long getMediaTimeForChildMediaTime(Void id, long mediaTimeMs) {
  if (mediaTimeMs == C.TIME_UNSET) {
    return C.TIME_UNSET;
  }
  long startMs = C.usToMs(startUs);
  long clippedTimeMs = Math.max(0, mediaTimeMs - startMs);
  if (endUs != C.TIME_END_OF_SOURCE) {
    clippedTimeMs = Math.min(C.usToMs(endUs) - startMs, clippedTimeMs);
  }
  return clippedTimeMs;
}
 
Example 15
Source File: AdPlaybackState.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the index of the next ad group after {@code positionUs} that has ads remaining to be
 * played. Returns {@link C#INDEX_UNSET} if there is no such ad group.
 *
 * @param positionUs The position after which to find an ad group, in microseconds.
 * @return The index of the ad group, or {@link C#INDEX_UNSET}.
 */
public int getAdGroupIndexAfterPositionUs(long positionUs) {
  // Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
  // In practice we expect there to be few ad groups so the search shouldn't be expensive.
  int index = 0;
  while (index < adGroupTimesUs.length
      && adGroupTimesUs[index] != C.TIME_END_OF_SOURCE
      && (positionUs >= adGroupTimesUs[index] || !adGroups[index].hasUnplayedAds())) {
    index++;
  }
  return index < adGroupTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 16
Source File: ClippingMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  long bufferedPositionUs = mediaPeriod.getBufferedPositionUs();
  if (bufferedPositionUs == C.TIME_END_OF_SOURCE
      || (endUs != C.TIME_END_OF_SOURCE && bufferedPositionUs >= endUs)) {
    return C.TIME_END_OF_SOURCE;
  }
  return bufferedPositionUs;
}
 
Example 17
Source File: MergingMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  long bufferedPositionUs = Long.MAX_VALUE;
  for (MediaPeriod period : enabledPeriods) {
    long rendererBufferedPositionUs = period.getBufferedPositionUs();
    if (rendererBufferedPositionUs != C.TIME_END_OF_SOURCE) {
      bufferedPositionUs = Math.min(bufferedPositionUs, rendererBufferedPositionUs);
    }
  }
  return bufferedPositionUs == Long.MAX_VALUE ? C.TIME_END_OF_SOURCE : bufferedPositionUs;
}
 
Example 18
Source File: ExtractorMediaPeriod.java    From K-Sonic with MIT License 4 votes vote down vote up
@Override
public long getNextLoadPositionUs() {
  return enabledTrackCount == 0 ? C.TIME_END_OF_SOURCE : getBufferedPositionUs();
}
 
Example 19
Source File: SingleSampleMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public long getNextLoadPositionUs() {
  return loadingFinished || loader.isLoading() ? C.TIME_END_OF_SOURCE : 0;
}
 
Example 20
Source File: SilenceMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  return C.TIME_END_OF_SOURCE;
}