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

The following examples show how to use com.google.android.exoplayer2.Timeline#Period . 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: AdsMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param adMediaSourceFactory Factory for media sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adViewProvider Provider of views for the ad UI.
 */
public AdsMediaSource(
    MediaSource contentMediaSource,
    MediaSourceFactory adMediaSourceFactory,
    AdsLoader adsLoader,
    AdsLoader.AdViewProvider adViewProvider) {
  this.contentMediaSource = contentMediaSource;
  this.adMediaSourceFactory = adMediaSourceFactory;
  this.adsLoader = adsLoader;
  this.adViewProvider = adViewProvider;
  mainHandler = new Handler(Looper.getMainLooper());
  deferredMediaPeriodByAdMediaSource = new HashMap<>();
  period = new Timeline.Period();
  adGroupMediaSources = new MediaSource[0][];
  adGroupTimelines = new Timeline[0][];
  adsLoader.setSupportedContentTypes(adMediaSourceFactory.getSupportedTypes());
}
 
Example 2
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param adMediaSourceFactory Factory for media sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adViewProvider Provider of views for the ad UI.
 */
public AdsMediaSource(
    MediaSource contentMediaSource,
    MediaSourceFactory adMediaSourceFactory,
    AdsLoader adsLoader,
    AdsLoader.AdViewProvider adViewProvider) {
  this.contentMediaSource = contentMediaSource;
  this.adMediaSourceFactory = adMediaSourceFactory;
  this.adsLoader = adsLoader;
  this.adViewProvider = adViewProvider;
  mainHandler = new Handler(Looper.getMainLooper());
  deferredMediaPeriodByAdMediaSource = new HashMap<>();
  period = new Timeline.Period();
  adGroupMediaSources = new MediaSource[0][];
  adGroupTimelines = new Timeline[0][];
  adsLoader.setSupportedContentTypes(adMediaSourceFactory.getSupportedTypes());
}
 
Example 3
Source File: ConcatenatingMediaSource.java    From Telegram 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 4
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param adMediaSourceFactory Factory for media sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated To listen for ad load error events, add a listener via {@link
 *     #addEventListener(Handler, MediaSourceEventListener)} and check for {@link
 *     AdLoadException}s in {@link MediaSourceEventListener#onLoadError(int, MediaPeriodId,
 *     LoadEventInfo, MediaLoadData, IOException, boolean)}. Individual ads loader implementations
 *     should expose ad interaction events, if applicable.
 */
@Deprecated
public AdsMediaSource(
    MediaSource contentMediaSource,
    MediaSourceFactory adMediaSourceFactory,
    AdsLoader adsLoader,
    ViewGroup adUiViewGroup,
    @Nullable Handler eventHandler,
    @Nullable EventListener eventListener) {
  this.contentMediaSource = contentMediaSource;
  this.adMediaSourceFactory = adMediaSourceFactory;
  this.adsLoader = adsLoader;
  this.adUiViewGroup = adUiViewGroup;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  mainHandler = new Handler(Looper.getMainLooper());
  deferredMediaPeriodByAdMediaSource = new HashMap<>();
  period = new Timeline.Period();
  adGroupMediaSources = new MediaSource[0][];
  adDurationsUs = new long[0][];
  adsLoader.setSupportedContentTypes(adMediaSourceFactory.getSupportedTypes());
}
 
Example 5
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param adMediaSourceFactory Factory for media sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated To listen for ad load error events, add a listener via {@link
 *     #addEventListener(Handler, MediaSourceEventListener)} and check for {@link
 *     AdLoadException}s in {@link MediaSourceEventListener#onLoadError(int, MediaPeriodId,
 *     LoadEventInfo, MediaLoadData, IOException, boolean)}. Individual ads loader implementations
 *     should expose ad interaction events, if applicable.
 */
@Deprecated
public AdsMediaSource(
    MediaSource contentMediaSource,
    MediaSourceFactory adMediaSourceFactory,
    AdsLoader adsLoader,
    ViewGroup adUiViewGroup,
    @Nullable Handler eventHandler,
    @Nullable EventListener eventListener) {
  this.contentMediaSource = contentMediaSource;
  this.adMediaSourceFactory = adMediaSourceFactory;
  this.adsLoader = adsLoader;
  this.adUiViewGroup = adUiViewGroup;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  mainHandler = new Handler(Looper.getMainLooper());
  deferredMediaPeriodByAdMediaSource = new HashMap<>();
  period = new Timeline.Period();
  adGroupMediaSources = new MediaSource[0][];
  adDurationsUs = new long[0][];
  adsLoader.setSupportedContentTypes(adMediaSourceFactory.getSupportedTypes());
}
 
Example 6
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 7
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 8
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 9
Source File: AdsMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static long[][] getAdDurations(
    @NullableType 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 10
Source File: ExtractorMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 */
public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler,
    EventListener eventListener, String customCacheKey) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  this.customCacheKey = customCacheKey;
  period = new Timeline.Period();
}
 
Example 11
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 12
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 13
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 14
Source File: EventLogger.java    From PowerFileExplorer with GNU General Public License v3.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 15
Source File: EventLogger.java    From TubiPlayer with MIT License 4 votes vote down vote up
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
    this.trackSelector = trackSelector;
    window = new Timeline.Window();
    period = new Timeline.Period();
    startTimeMs = SystemClock.elapsedRealtime();
}
 
Example 16
Source File: EventLogger.java    From ExoPlayer-Offline 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 17
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 18
Source File: EventLogger.java    From mimi-reader 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 GSYVideoPlayer 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: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Creates the masking media source.
 *
 * @param mediaSource A {@link MediaSource}.
 * @param useLazyPreparation Whether the {@code mediaSource} is 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.
 */
public MaskingMediaSource(MediaSource mediaSource, boolean useLazyPreparation) {
  this.mediaSource = mediaSource;
  this.useLazyPreparation = useLazyPreparation;
  window = new Timeline.Window();
  period = new Timeline.Period();
  timeline = MaskingTimeline.createWithDummyTimeline(mediaSource.getTag());
}