Java Code Examples for com.google.android.exoplayer2.Timeline#Window

The following examples show how to use com.google.android.exoplayer2.Timeline#Window . 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: ConcatenatingMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param isAtomic Whether the concatenating media source will be treated as atomic, i.e., treated
 *     as a single item for repeating and shuffling.
 * @param useLazyPreparation Whether playlist items are prepared lazily. If false, all manifest
 *     loads and other initial preparation steps happen immediately. If true, these initial
 *     preparations are triggered only when the player starts buffering the media.
 * @param shuffleOrder The {@link ShuffleOrder} to use when shuffling the child media sources.
 * @param mediaSources The {@link MediaSource}s to concatenate. It is valid for the same {@link
 *     MediaSource} instance to be present more than once in the array.
 */
@SuppressWarnings("initialization")
public ConcatenatingMediaSource(
    boolean isAtomic,
    boolean useLazyPreparation,
    ShuffleOrder shuffleOrder,
    MediaSource... mediaSources) {
  for (MediaSource mediaSource : mediaSources) {
    Assertions.checkNotNull(mediaSource);
  }
  this.shuffleOrder = shuffleOrder.getLength() > 0 ? shuffleOrder.cloneAndClear() : shuffleOrder;
  this.mediaSourceByMediaPeriod = new IdentityHashMap<>();
  this.mediaSourceByUid = new HashMap<>();
  this.mediaSourcesPublic = new ArrayList<>();
  this.mediaSourceHolders = new ArrayList<>();
  this.nextTimelineUpdateOnCompletionActions = new HashSet<>();
  this.pendingOnCompletionActions = new HashSet<>();
  this.isAtomic = isAtomic;
  this.useLazyPreparation = useLazyPreparation;
  window = new Timeline.Window();
  period = new Timeline.Period();
  addMediaSources(Arrays.asList(mediaSources));
}
 
Example 2
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * TODO: Expose this
 * Returns the position in the media. If <code>limitToCurrentWindow</code> is <code>true</code> then the position
 * in the current window will be returned, otherwise the total position across all windows will be returned.
 * These should only be different if the media in playback has multiple windows (e.g. in the case of using a
 * <code>ConcatenatingMediaSource</code> with more than 1 source)
 *
 * @param limitToCurrentWindow If <code>true</code> the position within the current window will be returned
 * @return The current position in the media
 */
public long getCurrentPosition(boolean limitToCurrentWindow) {
    long positionInCurrentWindow = player.getCurrentPosition();
    if (limitToCurrentWindow) {
        return positionInCurrentWindow;
    }

    // TODO cache the total time at the start of each window (e.g. Map<WindowIndex, cumulativeStartTimeMs>)
    // Adds the preceding window durations
    Timeline timeline = player.getCurrentTimeline();
    int maxWindowIndex = Math.min(timeline.getWindowCount() - 1, player.getCurrentWindowIndex());

    long cumulativePositionMs = 0;
    Timeline.Window window = new Timeline.Window();

    for (int index = 0; index < maxWindowIndex; index++) {
        timeline.getWindow(index, window);
        cumulativePositionMs += window.getDurationMs();
    }

    return cumulativePositionMs + positionInCurrentWindow;
}
 
Example 3
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates download helper.
 *
 * @param downloadType A download type. This value will be used as {@link DownloadRequest#type}.
 * @param uri A {@link Uri}.
 * @param cacheKey An optional cache key.
 * @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track
 *     selection needs to be made.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks
 *     are selected.
 */
public DownloadHelper(
    String downloadType,
    Uri uri,
    @Nullable String cacheKey,
    @Nullable MediaSource mediaSource,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    RendererCapabilities[] rendererCapabilities) {
  this.downloadType = downloadType;
  this.uri = uri;
  this.cacheKey = cacheKey;
  this.mediaSource = mediaSource;
  this.trackSelector =
      new DefaultTrackSelector(trackSelectorParameters, new DownloadTrackSelection.Factory());
  this.rendererCapabilities = rendererCapabilities;
  this.scratchSet = new SparseIntArray();
  trackSelector.init(/* listener= */ () -> {}, new DummyBandwidthMeter());
  callbackHandler = new Handler(Util.getLooper());
  window = new Timeline.Window();
}
 
Example 4
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@Nullable
public WindowInfo getWindowInfo() {
    Timeline timeline = player.getCurrentTimeline();
    if (timeline.isEmpty()) {
        return null;
    }

    int currentWindowIndex = player.getCurrentWindowIndex();
    Timeline.Window currentWindow = timeline.getWindow(currentWindowIndex, new Timeline.Window(), true);

    return new WindowInfo(
            player.getPreviousWindowIndex(),
            currentWindowIndex,
            player.getNextWindowIndex(),
            currentWindow
    );
}
 
Example 5
Source File: ConcatenatingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param isAtomic Whether the concatenating media source will be treated as atomic, i.e., treated
 *     as a single item for repeating and shuffling.
 * @param useLazyPreparation Whether playlist items are prepared lazily. If false, all manifest
 *     loads and other initial preparation steps happen immediately. If true, these initial
 *     preparations are triggered only when the player starts buffering the media.
 * @param shuffleOrder The {@link ShuffleOrder} to use when shuffling the child media sources.
 * @param mediaSources The {@link MediaSource}s to concatenate. It is valid for the same {@link
 *     MediaSource} instance to be present more than once in the array.
 */
@SuppressWarnings("initialization")
public ConcatenatingMediaSource(
    boolean isAtomic,
    boolean useLazyPreparation,
    ShuffleOrder shuffleOrder,
    MediaSource... mediaSources) {
  for (MediaSource mediaSource : mediaSources) {
    Assertions.checkNotNull(mediaSource);
  }
  this.shuffleOrder = shuffleOrder.getLength() > 0 ? shuffleOrder.cloneAndClear() : shuffleOrder;
  this.mediaSourceByMediaPeriod = new IdentityHashMap<>();
  this.mediaSourcesPublic = new ArrayList<>();
  this.mediaSourceHolders = new ArrayList<>();
  this.pendingOnCompletionActions = new ArrayList<>();
  this.query = new MediaSourceHolder(/* mediaSource= */ null);
  this.isAtomic = isAtomic;
  this.useLazyPreparation = useLazyPreparation;
  window = new Timeline.Window();
  addMediaSources(Arrays.asList(mediaSources));
}
 
Example 6
Source File: ExoVideoPlaybackControlView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the specified {@code timeline} can be shown on a multi-window time bar.
 *
 * @param timeline The {@link Timeline} to check.
 * @param window   A scratch {@link Timeline.Window} instance.
 * @return Whether the specified timeline can be shown on a multi-window time bar.
 */
private static boolean canShowMultiWindowTimeBar(Timeline timeline, Timeline.Window window) {
    if (timeline.getWindowCount() > MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR) {
        return false;
    }
    int windowCount = timeline.getWindowCount();
    for (int i = 0; i < windowCount; i++) {
        if (timeline.getWindow(i, window).durationUs == C.TIME_UNSET) {
            return false;
        }
    }
    return true;
}
 
Example 7
Source File: DefaultPlaybackSessionManager.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Creates session manager. */
public DefaultPlaybackSessionManager() {
  window = new Timeline.Window();
  period = new Timeline.Period();
  sessions = new HashMap<>();
  currentTimeline = Timeline.EMPTY;
}
 
Example 8
Source File: EventLogger.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 9
Source File: EventLogger.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 10
Source File: EventLogger.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 11
Source File: EventLogger.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();

  listeners = new CopyOnWriteArrayList<>();
}
 
Example 12
Source File: ReactExoplayerView.java    From react-native-video with MIT License 5 votes vote down vote up
public double getPositionInFirstPeriodMsForCurrentWindow(long currentPosition) {
    Timeline.Window window = new Timeline.Window();
    if(!player.getCurrentTimeline().isEmpty()) {    
        player.getCurrentTimeline().getWindow(player.getCurrentWindowIndex(), window);
    }
    return window.windowStartTimeMs + currentPosition;
}
 
Example 13
Source File: EventLogger.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 14
Source File: EventLogger.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates event logger.
 *
 * @param trackSelector The mapping track selector used by the player. May be null if detailed
 *     logging of track mapping is not required.
 * @param tag The tag used for logging.
 */
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
  this.trackSelector = trackSelector;
  this.tag = tag;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 15
Source File: WindowInfo.java    From ExoMedia with Apache License 2.0 4 votes vote down vote up
public WindowInfo(int previousWindowIndex, int currentWindowIndex, int nextWindowIndex, @NonNull Timeline.Window currentWindow) {
    this.previousWindowIndex = previousWindowIndex;
    this.currentWindowIndex = currentWindowIndex;
    this.nextWindowIndex = nextWindowIndex;
    this.currentWindow = currentWindow;
}
 
Example 16
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new clipping source that wraps the specified source.
 *
 * <p>If the start point is guaranteed to be a key frame, pass {@code false} to {@code
 * enableInitialPositionDiscontinuity} to suppress an initial discontinuity when a period is first
 * read from.
 *
 * <p>For live streams, if the clipping positions should move with the live window, pass {@code
 * true} to {@code allowDynamicClippingUpdates}. Otherwise, the live stream ends when the playback
 * reaches {@code endPositionUs} in the last reported live window at the time a media period was
 * created.
 *
 * @param mediaSource The single-period source to wrap.
 * @param startPositionUs The start position at which to start providing samples, in microseconds.
 *     If {@code relativeToDefaultPosition} is {@code false}, this position is relative to the
 *     start of the window in {@code mediaSource}'s timeline. If {@code relativeToDefaultPosition}
 *     is {@code true}, this position is relative to the default position in the window in {@code
 *     mediaSource}'s timeline.
 * @param endPositionUs The end position at which to stop providing samples, in microseconds.
 *     Specify {@link C#TIME_END_OF_SOURCE} to provide samples from the specified start point up
 *     to the end of the source. Specifying a position that exceeds the {@code mediaSource}'s
 *     duration will also result in the end of the source not being clipped. If {@code
 *     relativeToDefaultPosition} is {@code false}, the specified position is relative to the
 *     start of the window in {@code mediaSource}'s timeline. If {@code relativeToDefaultPosition}
 *     is {@code true}, this position is relative to the default position in the window in {@code
 *     mediaSource}'s timeline.
 * @param enableInitialDiscontinuity Whether the initial discontinuity should be enabled.
 * @param allowDynamicClippingUpdates Whether the clipping of active media periods moves with a
 *     live window. If {@code false}, playback ends when it reaches {@code endPositionUs} in the
 *     last reported live window at the time a media period was created.
 * @param relativeToDefaultPosition Whether {@code startPositionUs} and {@code endPositionUs} are
 *     relative to the default position in the window in {@code mediaSource}'s timeline.
 */
public ClippingMediaSource(
    MediaSource mediaSource,
    long startPositionUs,
    long endPositionUs,
    boolean enableInitialDiscontinuity,
    boolean allowDynamicClippingUpdates,
    boolean relativeToDefaultPosition) {
  Assertions.checkArgument(startPositionUs >= 0);
  this.mediaSource = Assertions.checkNotNull(mediaSource);
  startUs = startPositionUs;
  endUs = endPositionUs;
  this.enableInitialDiscontinuity = enableInitialDiscontinuity;
  this.allowDynamicClippingUpdates = allowDynamicClippingUpdates;
  this.relativeToDefaultPosition = relativeToDefaultPosition;
  mediaPeriods = new ArrayList<>();
  window = new Timeline.Window();
}
 
Example 17
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new clipping source that wraps the specified source.
 *
 * <p>If the start point is guaranteed to be a key frame, pass {@code false} to {@code
 * enableInitialPositionDiscontinuity} to suppress an initial discontinuity when a period is first
 * read from.
 *
 * <p>For live streams, if the clipping positions should move with the live window, pass {@code
 * true} to {@code allowDynamicClippingUpdates}. Otherwise, the live stream ends when the playback
 * reaches {@code endPositionUs} in the last reported live window at the time a media period was
 * created.
 *
 * @param mediaSource The single-period source to wrap.
 * @param startPositionUs The start position at which to start providing samples, in microseconds.
 *     If {@code relativeToDefaultPosition} is {@code false}, this position is relative to the
 *     start of the window in {@code mediaSource}'s timeline. If {@code relativeToDefaultPosition}
 *     is {@code true}, this position is relative to the default position in the window in {@code
 *     mediaSource}'s timeline.
 * @param endPositionUs The end position at which to stop providing samples, in microseconds.
 *     Specify {@link C#TIME_END_OF_SOURCE} to provide samples from the specified start point up
 *     to the end of the source. Specifying a position that exceeds the {@code mediaSource}'s
 *     duration will also result in the end of the source not being clipped. If {@code
 *     relativeToDefaultPosition} is {@code false}, the specified position is relative to the
 *     start of the window in {@code mediaSource}'s timeline. If {@code relativeToDefaultPosition}
 *     is {@code true}, this position is relative to the default position in the window in {@code
 *     mediaSource}'s timeline.
 * @param enableInitialDiscontinuity Whether the initial discontinuity should be enabled.
 * @param allowDynamicClippingUpdates Whether the clipping of active media periods moves with a
 *     live window. If {@code false}, playback ends when it reaches {@code endPositionUs} in the
 *     last reported live window at the time a media period was created.
 * @param relativeToDefaultPosition Whether {@code startPositionUs} and {@code endPositionUs} are
 *     relative to the default position in the window in {@code mediaSource}'s timeline.
 */
public ClippingMediaSource(
    MediaSource mediaSource,
    long startPositionUs,
    long endPositionUs,
    boolean enableInitialDiscontinuity,
    boolean allowDynamicClippingUpdates,
    boolean relativeToDefaultPosition) {
  Assertions.checkArgument(startPositionUs >= 0);
  this.mediaSource = Assertions.checkNotNull(mediaSource);
  startUs = startPositionUs;
  endUs = endPositionUs;
  this.enableInitialDiscontinuity = enableInitialDiscontinuity;
  this.allowDynamicClippingUpdates = allowDynamicClippingUpdates;
  this.relativeToDefaultPosition = relativeToDefaultPosition;
  mediaPeriods = new ArrayList<>();
  window = new Timeline.Window();
}
 
Example 18
Source File: EventLogger.java    From LiveVideoBroadcaster with Apache License 2.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
  this.trackSelector = trackSelector;
  window = new Timeline.Window();
  period = new Timeline.Period();
  startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 19
Source File: EventLogger.java    From TigerVideo with Apache License 2.0 4 votes vote down vote up
public EventLogger(MappingTrackSelector trackSelector) {
    this.trackSelector = trackSelector;
    window = new Timeline.Window();
    period = new Timeline.Period();
    startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 20
Source File: PlaybackControlView.java    From K-Sonic with MIT License 4 votes vote down vote up
public PlaybackControlView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  int controllerLayoutId = R.layout.exo_playback_control_view;
  rewindMs = DEFAULT_REWIND_MS;
  fastForwardMs = DEFAULT_FAST_FORWARD_MS;
  showTimeoutMs = DEFAULT_SHOW_TIMEOUT_MS;
  if (attrs != null) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
        R.styleable.PlaybackControlView, 0, 0);
    try {
      rewindMs = a.getInt(R.styleable.PlaybackControlView_rewind_increment, rewindMs);
      fastForwardMs = a.getInt(R.styleable.PlaybackControlView_fastforward_increment,
          fastForwardMs);
      showTimeoutMs = a.getInt(R.styleable.PlaybackControlView_show_timeout, showTimeoutMs);
      controllerLayoutId = a.getResourceId(R.styleable.PlaybackControlView_controller_layout_id,
          controllerLayoutId);
    } finally {
      a.recycle();
    }
  }
  currentWindow = new Timeline.Window();
  formatBuilder = new StringBuilder();
  formatter = new Formatter(formatBuilder, Locale.getDefault());
  componentListener = new ComponentListener();
  seekDispatcher = DEFAULT_SEEK_DISPATCHER;

  LayoutInflater.from(context).inflate(controllerLayoutId, this);
  setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);

  durationView = (TextView) findViewById(R.id.exo_duration);
  positionView = (TextView) findViewById(R.id.exo_position);
  progressBar = (SeekBar) findViewById(R.id.exo_progress);
  if (progressBar != null) {
    progressBar.setOnSeekBarChangeListener(componentListener);
    progressBar.setMax(PROGRESS_BAR_MAX);
  }
  playButton = findViewById(R.id.exo_play);
  if (playButton != null) {
    playButton.setOnClickListener(componentListener);
  }
  pauseButton = findViewById(R.id.exo_pause);
  if (pauseButton != null) {
    pauseButton.setOnClickListener(componentListener);
  }
  previousButton = findViewById(R.id.exo_prev);
  if (previousButton != null) {
    previousButton.setOnClickListener(componentListener);
  }
  nextButton = findViewById(R.id.exo_next);
  if (nextButton != null) {
    nextButton.setOnClickListener(componentListener);
  }
  rewindButton = findViewById(R.id.exo_rew);
  if (rewindButton != null) {
    rewindButton.setOnClickListener(componentListener);
  }
  fastForwardButton = findViewById(R.id.exo_ffwd);
  if (fastForwardButton != null) {
    fastForwardButton.setOnClickListener(componentListener);
  }
}