mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Simplify some buffered position related code.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=215704344
This commit is contained in:
parent
7849a5eb52
commit
9ca6544311
@ -496,10 +496,8 @@ import java.util.Collections;
|
||||
|
||||
// Update the buffered position and total buffered duration.
|
||||
MediaPeriodHolder loadingPeriod = queue.getLoadingPeriod();
|
||||
playbackInfo.bufferedPositionUs =
|
||||
loadingPeriod.getBufferedPositionUs(/* convertEosToDuration= */ true);
|
||||
playbackInfo.totalBufferedDurationUs =
|
||||
playbackInfo.bufferedPositionUs - loadingPeriod.toPeriodTime(rendererPositionUs);
|
||||
playbackInfo.bufferedPositionUs = loadingPeriod.getBufferedPositionUs();
|
||||
playbackInfo.totalBufferedDurationUs = getTotalBufferedDurationUs();
|
||||
}
|
||||
|
||||
private void doSomeWork() throws ExoPlaybackException, IOException {
|
||||
@ -1097,12 +1095,10 @@ import java.util.Collections;
|
||||
}
|
||||
// Renderers are ready and we're loading. Ask the LoadControl whether to transition.
|
||||
MediaPeriodHolder loadingHolder = queue.getLoadingPeriod();
|
||||
long bufferedPositionUs = loadingHolder.getBufferedPositionUs(!loadingHolder.info.isFinal);
|
||||
return bufferedPositionUs == C.TIME_END_OF_SOURCE
|
||||
boolean bufferedToEnd = loadingHolder.isFullyBuffered() && loadingHolder.info.isFinal;
|
||||
return bufferedToEnd
|
||||
|| loadControl.shouldStartPlayback(
|
||||
bufferedPositionUs - loadingHolder.toPeriodTime(rendererPositionUs),
|
||||
mediaClock.getPlaybackParameters().speed,
|
||||
rebuffering);
|
||||
getTotalBufferedDurationUs(), mediaClock.getPlaybackParameters().speed, rebuffering);
|
||||
}
|
||||
|
||||
private boolean isTimelineReady() {
|
||||
@ -1574,7 +1570,7 @@ import java.util.Collections;
|
||||
return;
|
||||
}
|
||||
long bufferedDurationUs =
|
||||
nextLoadPositionUs - loadingPeriodHolder.toPeriodTime(rendererPositionUs);
|
||||
getTotalBufferedDurationUs(/* bufferedPositionInLoadingPeriodUs= */ nextLoadPositionUs);
|
||||
boolean continueLoading =
|
||||
loadControl.shouldContinueLoading(
|
||||
bufferedDurationUs, mediaClock.getPlaybackParameters().speed);
|
||||
@ -1680,6 +1676,17 @@ import java.util.Collections;
|
||||
}
|
||||
}
|
||||
|
||||
private long getTotalBufferedDurationUs() {
|
||||
return getTotalBufferedDurationUs(playbackInfo.bufferedPositionUs);
|
||||
}
|
||||
|
||||
private long getTotalBufferedDurationUs(long bufferedPositionInLoadingPeriodUs) {
|
||||
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
|
||||
return loadingPeriodHolder == null
|
||||
? 0
|
||||
: bufferedPositionInLoadingPeriodUs - loadingPeriodHolder.toPeriodTime(rendererPositionUs);
|
||||
}
|
||||
|
||||
private void updateLoadControlTrackSelection(
|
||||
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
|
||||
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);
|
||||
|
@ -133,23 +133,18 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the buffered position in microseconds. If the period is buffered to the end then
|
||||
* {@link C#TIME_END_OF_SOURCE} is returned unless {@code convertEosToDuration} is true, in which
|
||||
* case the period duration is returned.
|
||||
* Returns the buffered position in microseconds. If the period is buffered to the end, then the
|
||||
* period duration is returned.
|
||||
*
|
||||
* @param convertEosToDuration Whether to return the period duration rather than
|
||||
* {@link C#TIME_END_OF_SOURCE} if the period is fully buffered.
|
||||
* @return The buffered position in microseconds.
|
||||
*/
|
||||
public long getBufferedPositionUs(boolean convertEosToDuration) {
|
||||
public long getBufferedPositionUs() {
|
||||
if (!prepared) {
|
||||
return info.startPositionUs;
|
||||
}
|
||||
long bufferedPositionUs =
|
||||
hasEnabledTracks ? mediaPeriod.getBufferedPositionUs() : C.TIME_END_OF_SOURCE;
|
||||
return bufferedPositionUs == C.TIME_END_OF_SOURCE && convertEosToDuration
|
||||
? info.durationUs
|
||||
: bufferedPositionUs;
|
||||
return bufferedPositionUs == C.TIME_END_OF_SOURCE ? info.durationUs : bufferedPositionUs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user