Skip to content

Commit

Permalink
Add a custom time bar view.
Browse files Browse the repository at this point in the history
Also add an isAd flag to Timeline.Period so that periods can be declared as
containing ads. The times of these periods are indicated using ad markers in
the new TimeBar.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151116208
  • Loading branch information
andrewlewis authored and ojw28 committed Mar 31, 2017
1 parent f4c33da commit 9d20a8d
Show file tree
Hide file tree
Showing 14 changed files with 951 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public int getPeriodCount() {
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
TimelineWindowDefinition windowDefinition = windowDefinitions[periodIndex];
Object id = setIds ? periodIndex : null;
return period.set(id, id, periodIndex, windowDefinition.durationUs, 0);
return period.set(id, id, periodIndex, windowDefinition.durationUs, 0, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,24 @@ public static final class Period {
*/
public long durationUs;

/**
* Whether this period contains an ad.
*/
public boolean isAd;

private long positionInWindowUs;

/**
* Sets the data held by this period.
*/
public Period set(Object id, Object uid, int windowIndex, long durationUs,
long positionInWindowUs) {
long positionInWindowUs, boolean isAd) {
this.id = id;
this.uid = uid;
this.windowIndex = windowIndex;
this.durationUs = durationUs;
this.positionInWindowUs = positionInWindowUs;
this.isAd = isAd;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public int getIndexOfPeriod(Object uid) {
int periodIndexOffset = loopCount * childPeriodCount;
return childTimeline.getIndexOfPeriod(loopCountAndChildUid.second) + periodIndexOffset;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int getPeriodCount() {
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
Assertions.checkIndex(periodIndex, 0, 1);
Object id = setIds ? ID : null;
return period.set(id, id, 0, periodDurationUs, -windowPositionInPeriodUs);
return period.set(id, id, 0, periodDurationUs, -windowPositionInPeriodUs, false);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Formatter;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -309,6 +310,18 @@ public static int constrainValue(int value, int min, int max) {
return Math.max(min, Math.min(value, max));
}

/**
* Constrains a value to the specified bounds.
*
* @param value The value to constrain.
* @param min The lower bound.
* @param max The upper bound.
* @return The constrained value {@code Math.max(min, Math.min(value, max))}.
*/
public static long constrainValue(long value, long min, long max) {
return Math.max(min, Math.min(value, max));
}

/**
* Constrains a value to the specified bounds.
*
Expand Down Expand Up @@ -835,6 +848,27 @@ public static int inferContentType(String fileName) {
}
}

/**
* Returns the specified millisecond time formatted as a string.
*
* @param builder The builder that {@code formatter} will write to.
* @param formatter The formatter.
* @param timeMs The time to format as a string, in milliseconds.
* @return The time formatted as a string.
*/
public static String getStringForTime(StringBuilder builder, Formatter formatter, long timeMs) {
if (timeMs == C.TIME_UNSET) {
timeMs = 0;
}
long totalSeconds = (timeMs + 500) / 1000;
long seconds = totalSeconds % 60;
long minutes = (totalSeconds / 60) % 60;
long hours = totalSeconds / 3600;
builder.setLength(0);
return hours > 0 ? formatter.format("%d:%02d:%02d", hours, minutes, seconds).toString()
: formatter.format("%02d:%02d", minutes, seconds).toString();
}

/**
* Maps a {@link C} {@code TRACK_TYPE_*} constant to the corresponding {@link C}
* {@code DEFAULT_*_BUFFER_SIZE} constant.
Expand Down
7 changes: 0 additions & 7 deletions library/core/src/main/proguard-rules.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public Period getPeriod(int periodIndex, Period period, boolean setIdentifiers)
+ Assertions.checkIndex(periodIndex, 0, manifest.getPeriodCount()) : null;
return period.set(id, uid, 0, manifest.getPeriodDurationUs(periodIndex),
C.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs)
- offsetInFirstPeriodUs);
- offsetInFirstPeriodUs, false);
}

@Override
Expand Down
Loading

0 comments on commit 9d20a8d

Please sign in to comment.