Commit 2a9d5c21 by tonihei Committed by Oliver Woodman

Clarify doc for Player.getDuration and add Player.getContentDuration.

Similar to getBufferedPosition and getCurrentPosition, getDuration should
mention that it also returns the duration of the current ad.

And, also similar to getContentBufferedDuration and getContentPosition, a
new method getContentDuration simplifies querying the content duration while
playing an ad.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209914696
parent 3f70454c
......@@ -568,6 +568,11 @@ public final class CastPlayer implements Player {
}
@Override
public long getContentDuration() {
return getDuration();
}
@Override
public boolean isLoading() {
return false;
}
......
......@@ -494,18 +494,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Override
public long getDuration() {
Timeline timeline = playbackInfo.timeline;
if (timeline.isEmpty()) {
return C.TIME_UNSET;
}
if (isPlayingAd()) {
MediaPeriodId periodId = playbackInfo.periodId;
timeline.getPeriodByUid(periodId.periodUid, period);
playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period);
long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup);
return C.usToMs(adDurationUs);
} else {
return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
}
return getContentDuration();
}
@Override
......@@ -571,6 +566,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Override
public long getContentDuration() {
return playbackInfo.timeline.isEmpty()
? C.TIME_UNSET
: playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
}
@Override
public long getContentPosition() {
if (isPlayingAd()) {
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
......
......@@ -748,8 +748,8 @@ public interface Player {
@Nullable Object getCurrentTag();
/**
* Returns the duration of the current window in milliseconds, or {@link C#TIME_UNSET} if the
* duration is not known.
* Returns the duration of the current content window or ad in milliseconds, or {@link
* C#TIME_UNSET} if the duration is not known.
*/
long getDuration();
......@@ -808,6 +808,13 @@ public interface Player {
int getCurrentAdIndexInAdGroup();
/**
* If {@link #isPlayingAd()} returns {@code true}, returns the duration of the current content
* window in milliseconds, or {@link C#TIME_UNSET} if the duration is not known. If there is no ad
* playing, the returned duration is the same as that returned by {@link #getDuration()}.
*/
long getContentDuration();
/**
* If {@link #isPlayingAd()} returns {@code true}, returns the content position that will be
* played once all ads in the ad group have finished playing, in milliseconds. If there is no ad
* playing, the returned position is the same as that returned by {@link #getCurrentPosition()}.
......
......@@ -1054,6 +1054,11 @@ public class SimpleExoPlayer
}
@Override
public long getContentDuration() {
return player.getContentDuration();
}
@Override
public long getContentPosition() {
return player.getContentPosition();
}
......
......@@ -300,6 +300,11 @@ public abstract class StubExoPlayer implements ExoPlayer {
}
@Override
public long getContentDuration() {
throw new UnsupportedOperationException();
}
@Override
public long getContentPosition() {
throw new UnsupportedOperationException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment