com.google.android.exoplayer2.source.DeferredMediaPeriod Java Examples

The following examples show how to use com.google.android.exoplayer2.source.DeferredMediaPeriod. 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-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void onAdSourceInfoRefreshed(MediaSource mediaSource, int adGroupIndex,
    int adIndexInAdGroup, Timeline timeline) {
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  adGroupTimelines[adGroupIndex][adIndexInAdGroup] = timeline;
  List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.remove(mediaSource);
  if (mediaPeriods != null) {
    Object periodUid = timeline.getUidOfPeriod(/* periodIndex= */ 0);
    for (int i = 0; i < mediaPeriods.size(); i++) {
      DeferredMediaPeriod mediaPeriod = mediaPeriods.get(i);
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(periodUid, mediaPeriod.id.windowSequenceNumber);
      mediaPeriod.createPeriod(adSourceMediaPeriodId);
    }
  }
  maybeUpdateSourceInfo();
}
 
Example #2
Source File: AdsMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void onAdSourceInfoRefreshed(MediaSource mediaSource, int adGroupIndex,
    int adIndexInAdGroup, Timeline timeline) {
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  adGroupTimelines[adGroupIndex][adIndexInAdGroup] = timeline;
  List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.remove(mediaSource);
  if (mediaPeriods != null) {
    Object periodUid = timeline.getUidOfPeriod(/* periodIndex= */ 0);
    for (int i = 0; i < mediaPeriods.size(); i++) {
      DeferredMediaPeriod mediaPeriod = mediaPeriods.get(i);
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(periodUid, mediaPeriod.id.windowSequenceNumber);
      mediaPeriod.createPeriod(adSourceMediaPeriodId);
    }
  }
  maybeUpdateSourceInfo();
}
 
Example #3
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
  DeferredMediaPeriod deferredMediaPeriod = (DeferredMediaPeriod) mediaPeriod;
  List<DeferredMediaPeriod> mediaPeriods =
      deferredMediaPeriodByAdMediaSource.get(deferredMediaPeriod.mediaSource);
  if (mediaPeriods != null) {
    mediaPeriods.remove(deferredMediaPeriod);
  }
  deferredMediaPeriod.releasePeriod();
}
 
Example #4
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onAdSourceInfoRefreshed(MediaSource mediaSource, int adGroupIndex,
    int adIndexInAdGroup, Timeline timeline) {
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  adDurationsUs[adGroupIndex][adIndexInAdGroup] = timeline.getPeriod(0, period).getDurationUs();
  List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.remove(mediaSource);
  if (mediaPeriods != null) {
    for (int i = 0; i < mediaPeriods.size(); i++) {
      DeferredMediaPeriod mediaPeriod = mediaPeriods.get(i);
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(/* periodIndex= */ 0, mediaPeriod.id.windowSequenceNumber);
      mediaPeriod.createPeriod(adSourceMediaPeriodId);
    }
  }
  maybeUpdateSourceInfo();
}
 
Example #5
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
  DeferredMediaPeriod deferredMediaPeriod = (DeferredMediaPeriod) mediaPeriod;
  List<DeferredMediaPeriod> mediaPeriods =
      deferredMediaPeriodByAdMediaSource.get(deferredMediaPeriod.mediaSource);
  if (mediaPeriods != null) {
    mediaPeriods.remove(deferredMediaPeriod);
  }
  deferredMediaPeriod.releasePeriod();
}
 
Example #6
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onAdSourceInfoRefreshed(MediaSource mediaSource, int adGroupIndex,
    int adIndexInAdGroup, Timeline timeline) {
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  adDurationsUs[adGroupIndex][adIndexInAdGroup] = timeline.getPeriod(0, period).getDurationUs();
  List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.remove(mediaSource);
  if (mediaPeriods != null) {
    for (int i = 0; i < mediaPeriods.size(); i++) {
      DeferredMediaPeriod mediaPeriod = mediaPeriods.get(i);
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(/* periodIndex= */ 0, mediaPeriod.id.windowSequenceNumber);
      mediaPeriod.createPeriod(adSourceMediaPeriodId);
    }
  }
  maybeUpdateSourceInfo();
}
 
Example #7
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
  DeferredMediaPeriod deferredMediaPeriod = (DeferredMediaPeriod) mediaPeriod;
  List<DeferredMediaPeriod> mediaPeriods =
      deferredMediaPeriodByAdMediaSource.get(deferredMediaPeriod.mediaSource);
  if (mediaPeriods != null) {
    mediaPeriods.remove(deferredMediaPeriod);
  }
  deferredMediaPeriod.releasePeriod();
}
 
Example #8
Source File: AdsMediaSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releasePeriod(MediaPeriod mediaPeriod) {
  DeferredMediaPeriod deferredMediaPeriod = (DeferredMediaPeriod) mediaPeriod;
  List<DeferredMediaPeriod> mediaPeriods =
      deferredMediaPeriodByAdMediaSource.get(deferredMediaPeriod.mediaSource);
  if (mediaPeriods != null) {
    mediaPeriods.remove(deferredMediaPeriod);
  }
  deferredMediaPeriod.releasePeriod();
}
 
Example #9
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  if (adPlaybackState.adGroupCount > 0 && id.isAd()) {
    int adGroupIndex = id.adGroupIndex;
    int adIndexInAdGroup = id.adIndexInAdGroup;
    Uri adUri = adPlaybackState.adGroups[adGroupIndex].uris[adIndexInAdGroup];
    if (adGroupMediaSources[adGroupIndex].length <= adIndexInAdGroup) {
      MediaSource adMediaSource = adMediaSourceFactory.createMediaSource(adUri);
      int oldAdCount = adGroupMediaSources[adGroupIndex].length;
      if (adIndexInAdGroup >= oldAdCount) {
        int adCount = adIndexInAdGroup + 1;
        adGroupMediaSources[adGroupIndex] =
            Arrays.copyOf(adGroupMediaSources[adGroupIndex], adCount);
        adDurationsUs[adGroupIndex] = Arrays.copyOf(adDurationsUs[adGroupIndex], adCount);
        Arrays.fill(adDurationsUs[adGroupIndex], oldAdCount, adCount, C.TIME_UNSET);
      }
      adGroupMediaSources[adGroupIndex][adIndexInAdGroup] = adMediaSource;
      deferredMediaPeriodByAdMediaSource.put(adMediaSource, new ArrayList<>());
      prepareChildSource(id, adMediaSource);
    }
    MediaSource mediaSource = adGroupMediaSources[adGroupIndex][adIndexInAdGroup];
    DeferredMediaPeriod deferredMediaPeriod = new DeferredMediaPeriod(mediaSource, id, allocator);
    deferredMediaPeriod.setPrepareErrorListener(
        new AdPrepareErrorListener(adUri, adGroupIndex, adIndexInAdGroup));
    List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.get(mediaSource);
    if (mediaPeriods == null) {
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(/* periodIndex= */ 0, id.windowSequenceNumber);
      deferredMediaPeriod.createPeriod(adSourceMediaPeriodId);
    } else {
      // Keep track of the deferred media period so it can be populated with the real media period
      // when the source's info becomes available.
      mediaPeriods.add(deferredMediaPeriod);
    }
    return deferredMediaPeriod;
  } else {
    DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(contentMediaSource, id, allocator);
    mediaPeriod.createPeriod(id);
    return mediaPeriod;
  }
}
 
Example #10
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  if (adPlaybackState.adGroupCount > 0 && id.isAd()) {
    int adGroupIndex = id.adGroupIndex;
    int adIndexInAdGroup = id.adIndexInAdGroup;
    Uri adUri = adPlaybackState.adGroups[adGroupIndex].uris[adIndexInAdGroup];
    if (adGroupMediaSources[adGroupIndex].length <= adIndexInAdGroup) {
      MediaSource adMediaSource = adMediaSourceFactory.createMediaSource(adUri);
      int oldAdCount = adGroupMediaSources[adGroupIndex].length;
      if (adIndexInAdGroup >= oldAdCount) {
        int adCount = adIndexInAdGroup + 1;
        adGroupMediaSources[adGroupIndex] =
            Arrays.copyOf(adGroupMediaSources[adGroupIndex], adCount);
        adDurationsUs[adGroupIndex] = Arrays.copyOf(adDurationsUs[adGroupIndex], adCount);
        Arrays.fill(adDurationsUs[adGroupIndex], oldAdCount, adCount, C.TIME_UNSET);
      }
      adGroupMediaSources[adGroupIndex][adIndexInAdGroup] = adMediaSource;
      deferredMediaPeriodByAdMediaSource.put(adMediaSource, new ArrayList<>());
      prepareChildSource(id, adMediaSource);
    }
    MediaSource mediaSource = adGroupMediaSources[adGroupIndex][adIndexInAdGroup];
    DeferredMediaPeriod deferredMediaPeriod = new DeferredMediaPeriod(mediaSource, id, allocator);
    deferredMediaPeriod.setPrepareErrorListener(
        new AdPrepareErrorListener(adUri, adGroupIndex, adIndexInAdGroup));
    List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.get(mediaSource);
    if (mediaPeriods == null) {
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(/* periodIndex= */ 0, id.windowSequenceNumber);
      deferredMediaPeriod.createPeriod(adSourceMediaPeriodId);
    } else {
      // Keep track of the deferred media period so it can be populated with the real media period
      // when the source's info becomes available.
      mediaPeriods.add(deferredMediaPeriod);
    }
    return deferredMediaPeriod;
  } else {
    DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(contentMediaSource, id, allocator);
    mediaPeriod.createPeriod(id);
    return mediaPeriod;
  }
}
 
Example #11
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  if (adPlaybackState.adGroupCount > 0 && id.isAd()) {
    int adGroupIndex = id.adGroupIndex;
    int adIndexInAdGroup = id.adIndexInAdGroup;
    Uri adUri = adPlaybackState.adGroups[adGroupIndex].uris[adIndexInAdGroup];
    if (adGroupMediaSources[adGroupIndex].length <= adIndexInAdGroup) {
      MediaSource adMediaSource = adMediaSourceFactory.createMediaSource(adUri);
      int oldAdCount = adGroupMediaSources[adGroupIndex].length;
      if (adIndexInAdGroup >= oldAdCount) {
        int adCount = adIndexInAdGroup + 1;
        adGroupMediaSources[adGroupIndex] =
            Arrays.copyOf(adGroupMediaSources[adGroupIndex], adCount);
        adGroupTimelines[adGroupIndex] = Arrays.copyOf(adGroupTimelines[adGroupIndex], adCount);
      }
      adGroupMediaSources[adGroupIndex][adIndexInAdGroup] = adMediaSource;
      deferredMediaPeriodByAdMediaSource.put(adMediaSource, new ArrayList<>());
      prepareChildSource(id, adMediaSource);
    }
    MediaSource mediaSource = adGroupMediaSources[adGroupIndex][adIndexInAdGroup];
    DeferredMediaPeriod deferredMediaPeriod =
        new DeferredMediaPeriod(mediaSource, id, allocator, startPositionUs);
    deferredMediaPeriod.setPrepareErrorListener(
        new AdPrepareErrorListener(adUri, adGroupIndex, adIndexInAdGroup));
    List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.get(mediaSource);
    if (mediaPeriods == null) {
      Object periodUid =
          adGroupTimelines[adGroupIndex][adIndexInAdGroup].getUidOfPeriod(/* periodIndex= */ 0);
      MediaPeriodId adSourceMediaPeriodId = new MediaPeriodId(periodUid, id.windowSequenceNumber);
      deferredMediaPeriod.createPeriod(adSourceMediaPeriodId);
    } else {
      // Keep track of the deferred media period so it can be populated with the real media period
      // when the source's info becomes available.
      mediaPeriods.add(deferredMediaPeriod);
    }
    return deferredMediaPeriod;
  } else {
    DeferredMediaPeriod mediaPeriod =
        new DeferredMediaPeriod(contentMediaSource, id, allocator, startPositionUs);
    mediaPeriod.createPeriod(id);
    return mediaPeriod;
  }
}
 
Example #12
Source File: AdsMediaSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  if (adPlaybackState.adGroupCount > 0 && id.isAd()) {
    int adGroupIndex = id.adGroupIndex;
    int adIndexInAdGroup = id.adIndexInAdGroup;
    Uri adUri = adPlaybackState.adGroups[adGroupIndex].uris[adIndexInAdGroup];
    if (adGroupMediaSources[adGroupIndex].length <= adIndexInAdGroup) {
      MediaSource adMediaSource = adMediaSourceFactory.createMediaSource(adUri);
      int oldAdCount = adGroupMediaSources[adGroupIndex].length;
      if (adIndexInAdGroup >= oldAdCount) {
        int adCount = adIndexInAdGroup + 1;
        adGroupMediaSources[adGroupIndex] =
            Arrays.copyOf(adGroupMediaSources[adGroupIndex], adCount);
        adGroupTimelines[adGroupIndex] = Arrays.copyOf(adGroupTimelines[adGroupIndex], adCount);
      }
      adGroupMediaSources[adGroupIndex][adIndexInAdGroup] = adMediaSource;
      deferredMediaPeriodByAdMediaSource.put(adMediaSource, new ArrayList<>());
      prepareChildSource(id, adMediaSource);
    }
    MediaSource mediaSource = adGroupMediaSources[adGroupIndex][adIndexInAdGroup];
    DeferredMediaPeriod deferredMediaPeriod =
        new DeferredMediaPeriod(mediaSource, id, allocator, startPositionUs);
    deferredMediaPeriod.setPrepareErrorListener(
        new AdPrepareErrorListener(adUri, adGroupIndex, adIndexInAdGroup));
    List<DeferredMediaPeriod> mediaPeriods = deferredMediaPeriodByAdMediaSource.get(mediaSource);
    if (mediaPeriods == null) {
      Object periodUid =
          adGroupTimelines[adGroupIndex][adIndexInAdGroup].getUidOfPeriod(/* periodIndex= */ 0);
      MediaPeriodId adSourceMediaPeriodId = new MediaPeriodId(periodUid, id.windowSequenceNumber);
      deferredMediaPeriod.createPeriod(adSourceMediaPeriodId);
    } else {
      // Keep track of the deferred media period so it can be populated with the real media period
      // when the source's info becomes available.
      mediaPeriods.add(deferredMediaPeriod);
    }
    return deferredMediaPeriod;
  } else {
    DeferredMediaPeriod mediaPeriod =
        new DeferredMediaPeriod(contentMediaSource, id, allocator, startPositionUs);
    mediaPeriod.createPeriod(id);
    return mediaPeriod;
  }
}