com.google.android.exoplayer2.Timeline Java Examples
The following examples show how to use
com.google.android.exoplayer2.Timeline.
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: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: ConcatenatingMediaSource.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * @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 #3
Source File: PlaybackControlView.java From K-Sonic with MIT License | 6 votes |
private void updateNavigation() { if (!isVisible() || !isAttachedToWindow) { return; } Timeline currentTimeline = player != null ? player.getCurrentTimeline() : null; boolean haveNonEmptyTimeline = currentTimeline != null && !currentTimeline.isEmpty(); boolean isSeekable = false; boolean enablePrevious = false; boolean enableNext = false; if (haveNonEmptyTimeline) { int currentWindowIndex = player.getCurrentWindowIndex(); currentTimeline.getWindow(currentWindowIndex, currentWindow); isSeekable = currentWindow.isSeekable; enablePrevious = currentWindowIndex > 0 || isSeekable || !currentWindow.isDynamic; enableNext = (currentWindowIndex < currentTimeline.getWindowCount() - 1) || currentWindow.isDynamic; } setButtonEnabled(enablePrevious , previousButton); setButtonEnabled(enableNext, nextButton); setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton); setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton); if (progressBar != null) { progressBar.setEnabled(isSeekable); } }
Example #4
Source File: ConcatenatingMediaSource.java From MediaSDK with Apache License 2.0 | 6 votes |
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) { if (mediaSourceHolder == null) { throw new IllegalArgumentException(); } if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) { MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1); int windowOffsetUpdate = timeline.getWindowCount() - (nextHolder.firstWindowIndexInChild - mediaSourceHolder.firstWindowIndexInChild); if (windowOffsetUpdate != 0) { correctOffsets( mediaSourceHolder.childIndex + 1, /* childIndexUpdate= */ 0, windowOffsetUpdate); } } scheduleTimelineUpdate(); }
Example #5
Source File: EventLogger.java From LiveVideoBroadcaster with Apache License 2.0 | 6 votes |
@Override public void onTimelineChanged(Timeline timeline, Object manifest) { int periodCount = timeline.getPeriodCount(); int windowCount = timeline.getWindowCount(); Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getPeriod(i, period); Log.d(TAG, " " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getWindow(i, window); Log.d(TAG, " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } Log.d(TAG, "]"); }
Example #6
Source File: CustomizeControlView.java From bcm-android with GNU General Public License v3.0 | 6 votes |
private void updateNavigation() { if (!isVisible() || !isAttachedToWindow) { return; } Timeline timeline = player != null ? player.getCurrentTimeline() : null; boolean haveNonEmptyTimeline = timeline != null && !timeline.isEmpty(); boolean isSeekable = false; boolean enablePrevious = false; boolean enableNext = false; if (haveNonEmptyTimeline && !player.isPlayingAd()) { int windowIndex = player.getCurrentWindowIndex(); timeline.getWindow(windowIndex, window); isSeekable = window.isSeekable; enablePrevious = isSeekable || !window.isDynamic || player.getPreviousWindowIndex() != C.INDEX_UNSET; enableNext = window.isDynamic || player.getNextWindowIndex() != C.INDEX_UNSET; } setButtonEnabled(enablePrevious, previousButton); setButtonEnabled(enableNext, nextButton); setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton); setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton); if (timeBar != null) { timeBar.setEnabled(isSeekable); } }
Example #7
Source File: ConcatenatingMediaSource.java From K-Sonic with MIT License | 6 votes |
private void handleSourceInfoRefreshed(int sourceFirstIndex, Timeline sourceTimeline, Object sourceManifest) { // Set the timeline and manifest. timelines[sourceFirstIndex] = sourceTimeline; manifests[sourceFirstIndex] = sourceManifest; // Also set the timeline and manifest for any duplicate entries of the same source. for (int i = sourceFirstIndex + 1; i < mediaSources.length; i++) { if (mediaSources[i] == mediaSources[sourceFirstIndex]) { timelines[i] = sourceTimeline; manifests[i] = sourceManifest; } } for (Timeline timeline : timelines) { if (timeline == null) { // Don't invoke the listener until all sources have timelines. return; } } timeline = new ConcatenatedTimeline(timelines.clone()); listener.onSourceInfoRefreshed(timeline, manifests.clone()); }
Example #8
Source File: ConcatenatingMediaSource.java From K-Sonic with MIT License | 6 votes |
public ConcatenatedTimeline(Timeline[] timelines) { int[] sourcePeriodOffsets = new int[timelines.length]; int[] sourceWindowOffsets = new int[timelines.length]; int periodCount = 0; int windowCount = 0; for (int i = 0; i < timelines.length; i++) { Timeline timeline = timelines[i]; periodCount += timeline.getPeriodCount(); sourcePeriodOffsets[i] = periodCount; windowCount += timeline.getWindowCount(); sourceWindowOffsets[i] = windowCount; } this.timelines = timelines; this.sourcePeriodOffsets = sourcePeriodOffsets; this.sourceWindowOffsets = sourceWindowOffsets; }
Example #9
Source File: TokPlayer.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
@Override public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { LogUtil.i(TAG, "onTimelineChanged"); if (mOnVideoPlayerListener != null) { mOnVideoPlayerListener.onTimelineChanged(timeline, manifest); } }
Example #10
Source File: EventLogger.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * 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: ClippingMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
private void refreshClippedTimeline(Timeline timeline) { long windowStartUs; long windowEndUs; timeline.getWindow(/* windowIndex= */ 0, window); long windowPositionInPeriodUs = window.getPositionInFirstPeriodUs(); if (clippingTimeline == null || mediaPeriods.isEmpty() || allowDynamicClippingUpdates) { windowStartUs = startUs; windowEndUs = endUs; if (relativeToDefaultPosition) { long windowDefaultPositionUs = window.getDefaultPositionUs(); windowStartUs += windowDefaultPositionUs; windowEndUs += windowDefaultPositionUs; } periodStartUs = windowPositionInPeriodUs + windowStartUs; periodEndUs = endUs == C.TIME_END_OF_SOURCE ? C.TIME_END_OF_SOURCE : windowPositionInPeriodUs + windowEndUs; int count = mediaPeriods.size(); for (int i = 0; i < count; i++) { mediaPeriods.get(i).updateClipping(periodStartUs, periodEndUs); } } else { // Keep window fixed at previous period position. windowStartUs = periodStartUs - windowPositionInPeriodUs; windowEndUs = endUs == C.TIME_END_OF_SOURCE ? C.TIME_END_OF_SOURCE : periodEndUs - windowPositionInPeriodUs; } try { clippingTimeline = new ClippingTimeline(timeline, windowStartUs, windowEndUs); } catch (IllegalClippingException e) { clippingError = e; return; } refreshSourceInfo(clippingTimeline); }
Example #12
Source File: AnalyticsCollector.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private WindowAndMediaPeriodId updateMediaPeriodToNewTimeline( WindowAndMediaPeriodId mediaPeriod, Timeline newTimeline) { if (newTimeline.isEmpty() || timeline.isEmpty()) { return mediaPeriod; } Object uid = timeline.getUidOfPeriod(mediaPeriod.mediaPeriodId.periodIndex); int newPeriodIndex = newTimeline.getIndexOfPeriod(uid); if (newPeriodIndex == C.INDEX_UNSET) { return mediaPeriod; } int newWindowIndex = newTimeline.getPeriod(newPeriodIndex, period).windowIndex; return new WindowAndMediaPeriodId( newWindowIndex, mediaPeriod.mediaPeriodId.copyWithPeriodIndex(newPeriodIndex)); }
Example #13
Source File: ExtractorMediaSource.java From K-Sonic with MIT License | 5 votes |
@Override public void onSourceInfoRefreshed(Timeline newTimeline, Object manifest) { long newTimelineDurationUs = newTimeline.getPeriod(0, period).getDurationUs(); boolean newTimelineHasDuration = newTimelineDurationUs != C.TIME_UNSET; if (timelineHasDuration && !newTimelineHasDuration) { // Suppress source info changes that would make the duration unknown when it is already known. return; } timeline = newTimeline; timelineHasDuration = newTimelineHasDuration; sourceListener.onSourceInfoRefreshed(timeline, null); }
Example #14
Source File: AnalyticsCollector.java From MediaSDK with Apache License 2.0 | 5 votes |
private EventTime generateMediaPeriodEventTime( int windowIndex, @Nullable MediaPeriodId mediaPeriodId) { Assertions.checkNotNull(player); if (mediaPeriodId != null) { MediaPeriodInfo mediaPeriodInfo = mediaPeriodQueueTracker.getMediaPeriodInfo(mediaPeriodId); return mediaPeriodInfo != null ? generateEventTime(mediaPeriodInfo) : generateEventTime(Timeline.EMPTY, windowIndex, mediaPeriodId); } Timeline timeline = player.getCurrentTimeline(); boolean windowIsInTimeline = windowIndex < timeline.getWindowCount(); return generateEventTime( windowIsInTimeline ? timeline : Timeline.EMPTY, windowIndex, /* mediaPeriodId= */ null); }
Example #15
Source File: LoopingMediaSource.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override protected void onChildSourceInfoRefreshed( Void id, MediaSource mediaSource, Timeline timeline, @Nullable Object manifest) { childPeriodCount = timeline.getPeriodCount(); Timeline loopingTimeline = loopCount != Integer.MAX_VALUE ? new LoopingTimeline(timeline, loopCount) : new InfinitelyLoopingTimeline(timeline); refreshSourceInfo(loopingTimeline, manifest); }
Example #16
Source File: AnalyticsCollector.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public final void onTimelineChanged( Timeline timeline, Object manifest, @Player.TimelineChangeReason int reason) { mediaPeriodQueueTracker.onTimelineChanged(timeline); EventTime eventTime = generatePlayingMediaPeriodEventTime(); for (AnalyticsListener listener : listeners) { listener.onTimelineChanged(eventTime, reason); } }
Example #17
Source File: ReactExoplayerView.java From react-native-video with MIT License | 5 votes |
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 #18
Source File: ConcatenatingMediaSource.java From K-Sonic with MIT License | 5 votes |
/** * @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. */ public ConcatenatingMediaSource(MediaSource... mediaSources) { this.mediaSources = mediaSources; timelines = new Timeline[mediaSources.length]; manifests = new Object[mediaSources.length]; sourceIndexByMediaPeriod = new HashMap<>(); duplicateFlags = buildDuplicateFlags(mediaSources); }
Example #19
Source File: ConcatenatingMediaSource.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public DeferredTimeline cloneWithNewTimeline(Timeline timeline) { return new DeferredTimeline( timeline, replacedId == DUMMY_ID && timeline.getPeriodCount() > 0 ? timeline.getUidOfPeriod(0) : replacedId); }
Example #20
Source File: LoopingMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override protected void onChildSourceInfoRefreshed(Void id, MediaSource mediaSource, Timeline timeline) { Timeline loopingTimeline = loopCount != Integer.MAX_VALUE ? new LoopingTimeline(timeline, loopCount) : new InfinitelyLoopingTimeline(timeline); refreshSourceInfo(loopingTimeline); }
Example #21
Source File: EventLogger.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * 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 #22
Source File: MergingMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * @param compositeSequenceableLoaderFactory A factory to create composite * {@link SequenceableLoader}s for when this media source loads data from multiple streams * (video, audio etc...). * @param mediaSources The {@link MediaSource}s to merge. */ public MergingMediaSource(CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, MediaSource... mediaSources) { this.mediaSources = mediaSources; this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; pendingTimelineSources = new ArrayList<>(Arrays.asList(mediaSources)); periodCount = PERIOD_COUNT_UNSET; timelines = new Timeline[mediaSources.length]; }
Example #23
Source File: MergingMediaSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * @param compositeSequenceableLoaderFactory A factory to create composite * {@link SequenceableLoader}s for when this media source loads data from multiple streams * (video, audio etc...). * @param mediaSources The {@link MediaSource}s to merge. */ public MergingMediaSource(CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, MediaSource... mediaSources) { this.mediaSources = mediaSources; this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; pendingTimelineSources = new ArrayList<>(Arrays.asList(mediaSources)); periodCount = PERIOD_COUNT_UNSET; timelines = new Timeline[mediaSources.length]; }
Example #24
Source File: AdsMediaSource.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private static long[][] getAdDurations(Timeline[][] adTimelines, Timeline.Period period) { long[][] adDurations = new long[adTimelines.length][]; for (int i = 0; i < adTimelines.length; i++) { adDurations[i] = new long[adTimelines[i].length]; for (int j = 0; j < adTimelines[i].length; j++) { adDurations[i][j] = adTimelines[i][j] == null ? C.TIME_UNSET : adTimelines[i][j].getPeriod(/* periodIndex= */ 0, period).getDurationUs(); } } return adDurations; }
Example #25
Source File: AdsMediaSource.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void maybeUpdateSourceInfo() { if (adPlaybackState != null && contentTimeline != null) { adPlaybackState = adPlaybackState.withAdDurationsUs(getAdDurations(adGroupTimelines, period)); Timeline timeline = adPlaybackState.adGroupCount == 0 ? contentTimeline : new SinglePeriodAdTimeline(contentTimeline, adPlaybackState); refreshSourceInfo(timeline, contentManifest); } }
Example #26
Source File: ConcatenatingMediaSource.java From K-Sonic with MIT License | 5 votes |
@Override public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) { this.listener = listener; for (int i = 0; i < mediaSources.length; i++) { if (!duplicateFlags[i]) { final int index = i; mediaSources[i].prepareSource(player, false, new Listener() { @Override public void onSourceInfoRefreshed(Timeline timeline, Object manifest) { handleSourceInfoRefreshed(index, timeline, manifest); } }); } } }
Example #27
Source File: ConcatenatingMediaSource.java From MediaSDK with Apache License 2.0 | 5 votes |
private void removeMediaSourceInternal(int index) { MediaSourceHolder holder = mediaSourceHolders.remove(index); mediaSourceByUid.remove(holder.uid); Timeline oldTimeline = holder.mediaSource.getTimeline(); correctOffsets(index, /* childIndexUpdate= */ -1, -oldTimeline.getWindowCount()); holder.isRemoved = true; maybeReleaseChildSource(holder); }
Example #28
Source File: MergingMediaSource.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * @param compositeSequenceableLoaderFactory A factory to create composite * {@link SequenceableLoader}s for when this media source loads data from multiple streams * (video, audio etc...). * @param mediaSources The {@link MediaSource}s to merge. */ public MergingMediaSource(CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, MediaSource... mediaSources) { this.mediaSources = mediaSources; this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; pendingTimelineSources = new ArrayList<>(Arrays.asList(mediaSources)); periodCount = PERIOD_COUNT_UNSET; timelines = new Timeline[mediaSources.length]; }
Example #29
Source File: ExoVideoPlaybackControlView.java From ExoVideoView with Apache License 2.0 | 5 votes |
@Override public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { if (manifest instanceof HlsManifest) { HlsManifest hlsManifest = (HlsManifest) manifest; isHls = !hlsManifest.mediaPlaylist.hasEndTag && hlsManifest.mediaPlaylist.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_UNKNOWN; } else { isHls = false; } updateNavigation(); updateTimeBarMode(); updateProgress(); }
Example #30
Source File: ClippingMediaSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override protected void onChildSourceInfoRefreshed( Void id, MediaSource mediaSource, Timeline timeline, @Nullable Object manifest) { if (clippingError != null) { return; } this.manifest = manifest; refreshClippedTimeline(timeline); }