本文整理了Java中com.google.android.exoplayer2.Timeline.getPeriodByUid()
方法的一些代码示例,展示了Timeline.getPeriodByUid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timeline.getPeriodByUid()
方法的具体详情如下:
包路径:com.google.android.exoplayer2.Timeline
类名称:Timeline
方法名:getPeriodByUid
[英]Populates a Period with data for the period with the specified unique identifier.
[中]使用具有指定唯一标识符的时段数据填充时段。
代码示例来源:origin: google/ExoPlayer
@Override
public int getCurrentWindowIndex() {
if (shouldMaskPosition()) {
return maskingWindowIndex;
} else {
return playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period)
.windowIndex;
}
}
代码示例来源:origin: google/ExoPlayer
private long periodPositionUsToWindowPositionMs(MediaPeriodId periodId, long positionUs) {
long positionMs = C.usToMs(positionUs);
playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period);
positionMs += period.getPositionInWindowMs();
return positionMs;
}
代码示例来源:origin: google/ExoPlayer
@Override
protected FakeMediaPeriod createFakeMediaPeriod(
MediaPeriodId id,
TrackGroupArray trackGroupArray,
Allocator allocator,
EventDispatcher eventDispatcher,
@Nullable TransferListener transferListener) {
Period period = timeline.getPeriodByUid(id.periodUid, new Period());
return new FakeAdaptiveMediaPeriod(
trackGroupArray,
eventDispatcher,
allocator,
chunkSourceFactory,
period.durationUs,
transferListener);
}
代码示例来源:origin: google/ExoPlayer
@Override
public long getDuration() {
if (isPlayingAd()) {
MediaPeriodId periodId = playbackInfo.periodId;
playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period);
long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup);
return C.usToMs(adDurationUs);
}
return getContentDuration();
}
代码示例来源:origin: google/ExoPlayer
@Override
public long getContentPosition() {
if (isPlayingAd()) {
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.contentPositionUs);
} else {
return getCurrentPosition();
}
}
代码示例来源:origin: google/ExoPlayer
private MediaPeriodInfo getMediaPeriodInfo(
MediaPeriodId id, long contentPositionUs, long startPositionUs) {
timeline.getPeriodByUid(id.periodUid, period);
if (id.isAd()) {
if (!period.isAdAvailable(id.adGroupIndex, id.adIndexInAdGroup)) {
return null;
}
return getMediaPeriodInfoForAd(
id.periodUid,
id.adGroupIndex,
id.adIndexInAdGroup,
contentPositionUs,
id.windowSequenceNumber);
} else {
return getMediaPeriodInfoForContent(id.periodUid, startPositionUs, id.windowSequenceNumber);
}
}
代码示例来源:origin: google/ExoPlayer
@Override
protected FakeMediaPeriod createFakeMediaPeriod(
MediaPeriodId id,
TrackGroupArray trackGroupArray,
Allocator allocator,
EventDispatcher eventDispatcher,
@Nullable TransferListener transferListener) {
Period period = timeline.getPeriodByUid(id.periodUid, new Period());
return new FakeAdaptiveMediaPeriod(
trackGroupArray,
eventDispatcher,
allocator,
chunkSourceFactory,
period.durationUs,
transferListener);
}
代码示例来源:origin: google/ExoPlayer
@Override
public final Period getPeriodByUid(Object uid, Period period) {
Object childUid = getChildTimelineUidFromConcatenatedUid(uid);
Object periodUid = getChildPeriodUidFromConcatenatedUid(uid);
int childIndex = getChildIndexByChildUid(childUid);
int firstWindowIndexInChild = getFirstWindowIndexByChildIndex(childIndex);
getTimelineByChildIndex(childIndex).getPeriodByUid(periodUid, period);
period.windowIndex += firstWindowIndexInChild;
period.uid = uid;
return period;
}
代码示例来源:origin: google/ExoPlayer
private boolean isLastInPeriod(MediaPeriodId id) {
int adGroupCount = timeline.getPeriodByUid(id.periodUid, period).getAdGroupCount();
if (adGroupCount == 0) {
return true;
}
int lastAdGroupIndex = adGroupCount - 1;
boolean isAd = id.isAd();
if (period.getAdGroupTimeUs(lastAdGroupIndex) != C.TIME_END_OF_SOURCE) {
// There's no postroll ad.
return !isAd && id.endPositionUs == C.TIME_END_OF_SOURCE;
}
int postrollAdCount = period.getAdCountInAdGroup(lastAdGroupIndex);
if (postrollAdCount == C.LENGTH_UNSET) {
// We won't know if this is the last ad until we know how many postroll ads there are.
return false;
}
boolean isLastAd =
isAd && id.adGroupIndex == lastAdGroupIndex && id.adIndexInAdGroup == postrollAdCount - 1;
return isLastAd || (!isAd && period.getFirstAdIndexToPlay(lastAdGroupIndex) == postrollAdCount);
}
代码示例来源:origin: google/ExoPlayer
int windowIndex = timeline.getPeriodByUid(periodUid, period).windowIndex;
if (oldFrontPeriodUid != null) {
int oldFrontPeriodIndex = timeline.getIndexOfPeriod(oldFrontPeriodUid);
代码示例来源:origin: google/ExoPlayer
private MediaPeriodInfo getMediaPeriodInfoForContent(
Object periodUid, long startPositionUs, long windowSequenceNumber) {
int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(startPositionUs);
long endPositionUs =
nextAdGroupIndex == C.INDEX_UNSET
? C.TIME_END_OF_SOURCE
: period.getAdGroupTimeUs(nextAdGroupIndex);
MediaPeriodId id = new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs);
timeline.getPeriodByUid(id.periodUid, period);
boolean isLastInPeriod = isLastInPeriod(id);
boolean isLastInTimeline = isLastInTimeline(id, isLastInPeriod);
long durationUs =
endPositionUs == C.TIME_END_OF_SOURCE ? period.getDurationUs() : endPositionUs;
return new MediaPeriodInfo(
id, startPositionUs, C.TIME_UNSET, durationUs, isLastInPeriod, isLastInTimeline);
}
代码示例来源:origin: google/ExoPlayer
/**
* Returns new media period info based on specified {@code mediaPeriodInfo} but taking into
* account the current timeline. This method must only be called if the period is still part of
* the current timeline.
*
* @param info Media period info for a media period based on an old timeline.
* @return The updated media period info for the current timeline.
*/
public MediaPeriodInfo getUpdatedMediaPeriodInfo(MediaPeriodInfo info) {
boolean isLastInPeriod = isLastInPeriod(info.id);
boolean isLastInTimeline = isLastInTimeline(info.id, isLastInPeriod);
timeline.getPeriodByUid(info.id.periodUid, period);
long durationUs =
info.id.isAd()
? period.getAdDurationUs(info.id.adGroupIndex, info.id.adIndexInAdGroup)
: (info.id.endPositionUs == C.TIME_END_OF_SOURCE
? period.getDurationUs()
: info.id.endPositionUs);
return new MediaPeriodInfo(
info.id,
info.startPositionUs,
info.contentPositionUs,
durationUs,
isLastInPeriod,
isLastInTimeline);
}
代码示例来源:origin: google/ExoPlayer
/**
* Resolves the specified timeline period and position to a {@link MediaPeriodId} that should be
* played, returning an identifier for an ad group if one needs to be played before the specified
* position, or an identifier for a content media period if not.
*
* @param periodUid The uid of the timeline period to play.
* @param positionUs The next content position in the period to play.
* @param windowSequenceNumber The sequence number of the window in the buffered sequence of
* windows this period is part of.
* @return The identifier for the first media period to play, taking into account unplayed ads.
*/
private MediaPeriodId resolveMediaPeriodIdForAds(
Object periodUid, long positionUs, long windowSequenceNumber) {
timeline.getPeriodByUid(periodUid, period);
int adGroupIndex = period.getAdGroupIndexForPositionUs(positionUs);
if (adGroupIndex == C.INDEX_UNSET) {
int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(positionUs);
long endPositionUs =
nextAdGroupIndex == C.INDEX_UNSET
? C.TIME_END_OF_SOURCE
: period.getAdGroupTimeUs(nextAdGroupIndex);
return new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs);
} else {
int adIndexInAdGroup = period.getFirstAdIndexToPlay(adGroupIndex);
return new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber);
}
}
代码示例来源:origin: google/ExoPlayer
@Override
public long getContentBufferedPosition() {
if (shouldMaskPosition()) {
return maskingWindowPositionMs;
}
if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber
!= playbackInfo.periodId.windowSequenceNumber) {
return playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
}
long contentBufferedPositionUs = playbackInfo.bufferedPositionUs;
if (playbackInfo.loadingMediaPeriodId.isAd()) {
Timeline.Period loadingPeriod =
playbackInfo.timeline.getPeriodByUid(playbackInfo.loadingMediaPeriodId.periodUid, period);
contentBufferedPositionUs =
loadingPeriod.getAdGroupTimeUs(playbackInfo.loadingMediaPeriodId.adGroupIndex);
if (contentBufferedPositionUs == C.TIME_END_OF_SOURCE) {
contentBufferedPositionUs = loadingPeriod.durationUs;
}
}
return periodPositionUsToWindowPositionMs(
playbackInfo.loadingMediaPeriodId, contentBufferedPositionUs);
}
代码示例来源:origin: google/ExoPlayer
private MediaPeriodInfo getMediaPeriodInfoForAd(
Object periodUid,
int adGroupIndex,
int adIndexInAdGroup,
long contentPositionUs,
long windowSequenceNumber) {
MediaPeriodId id =
new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber);
boolean isLastInPeriod = isLastInPeriod(id);
boolean isLastInTimeline = isLastInTimeline(id, isLastInPeriod);
long durationUs =
timeline
.getPeriodByUid(id.periodUid, period)
.getAdDurationUs(id.adGroupIndex, id.adIndexInAdGroup);
long startPositionUs =
adIndexInAdGroup == period.getFirstAdIndexToPlay(adGroupIndex)
? period.getAdResumePositionUs()
: 0;
return new MediaPeriodInfo(
id,
startPositionUs,
contentPositionUs,
durationUs,
isLastInPeriod,
isLastInTimeline);
}
代码示例来源:origin: google/ExoPlayer
timeline.getPeriodByUid(currentPeriodId.periodUid, period);
if (currentPeriodId.isAd()) {
int adGroupIndex = currentPeriodId.adGroupIndex;
代码示例来源:origin: google/ExoPlayer
timeline, timeline.getPeriodByUid(newPeriodUid, period).windowIndex, C.TIME_UNSET);
newPeriodUid = defaultPosition.first;
contentPositionUs = defaultPosition.second;
内容来源于网络,如有侵权,请联系作者删除!