Skip to content

Commit

Permalink
Merge pull request #3 from DiceTechnology/feat/DORIS-246-dvr-changes
Browse files Browse the repository at this point in the history
Feat/DORIS-246 DVR changes
  • Loading branch information
marceltex authored Apr 14, 2020
2 parents ec9b1c4 + 6408e6b commit 9c46c75
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.novoda:bintray-release:0.9.1'
classpath 'com.google.android.gms:strict-version-matcher-plugin:1.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ public long getCurrentPosition() {
: lastReportedPositionMs;
}

@Override
public long getStartPosition() {
return 0;
}

@Override
public long getEndPosition() {
return getDuration();
}

@Override
public long getBufferedPosition() {
return getCurrentPosition();
Expand Down
3 changes: 3 additions & 0 deletions library/all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply from: '../../constants.gradle'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
3 changes: 3 additions & 0 deletions library/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply plugin: 'com.android.library'
apply from: '../../constants.gradle'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ public long getCurrentPosition() {
}
}

@Override
public long getStartPosition() {
return 0;
}

@Override
public long getEndPosition() {
return getDuration();
}

@Override
public long getBufferedPosition() {
if (isPlayingAd()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,18 @@ public void onTimelineChanged(Timeline timeline, @Nullable Object manifest) {
/** Returns the playback position in the current content window or ad, in milliseconds. */
long getCurrentPosition();

/**
* Returns the position in the current content window at which playback should start, in
* milliseconds. For live video streams with DVR content this will return a negative number.
* */
long getStartPosition();

/**
* Returns the position in the current content window at which playback should end, in
* milliseconds. For live video streams this will return {@code 0}.
*/
long getEndPosition();

/**
* Returns an estimate of the position in the current content window or ad up to which data is
* buffered, in milliseconds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,16 @@ public long getCurrentPosition() {
return player.getCurrentPosition();
}

@Override
public long getStartPosition() {
return 0;
}

@Override
public long getEndPosition() {
return getDuration();
}

@Override
public long getBufferedPosition() {
verifyApplicationThread();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.google.android.exoplayer2.util;

public final class DvrMiddleware {

/**
* The time, in milliseconds, to use as the end position for a live DVR window.
*/
public static final long LIVE_DVR_END_POSITION = 0;
/**
* The length of one video segment in milliseconds.
*/
private static final long SEGMENT_LENGTH_MS = 6000;

/**
* Converts a positive position, in milliseconds, to a negative position. A negative position
* is typically required for live DVR windows.
*
* @param positionMs The positive position, in milliseconds, to be converted.
* @param durationMs The duration of the current content window, in milliseconds.
* @return A {@code long} position in milliseconds. This will always be negative.
* @throws IllegalArgumentException If {@param positionMs} isn't positive.
*/
public static long convertToNegativePosition(long positionMs, long durationMs) {
Assertions.checkArgument(positionMs >= -1 * SEGMENT_LENGTH_MS);
return positionMs - durationMs;
}

/**
* Converts a negative position, in milliseconds, to a positive position. A positive position
* is typically required for VOD windows.
*
* @param positionMs The negative position, in milliseconds, to be converted.
* @param durationMs The duration of the current content window, in milliseconds.
* @return A {@code long} position in milliseconds. This will always be positive.
* @throws IllegalArgumentException If {@param positionMs} isn't negative.
*/
public static long convertToPositivePosition(long positionMs, long durationMs) {
Assertions.checkArgument(positionMs <= 0);
return positionMs + durationMs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.android.exoplayer2.util;

import static android.content.Context.UI_MODE_SERVICE;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand Down Expand Up @@ -45,7 +43,9 @@
import android.view.Display;
import android.view.SurfaceView;
import android.view.WindowManager;

import androidx.annotation.Nullable;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.Format;
Expand All @@ -57,6 +57,12 @@
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.video.VideoRendererEventListener;

import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.nullness.compatqual.NullableType;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.PolyNull;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
Expand All @@ -82,10 +88,8 @@
import java.util.regex.Pattern;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.nullness.compatqual.NullableType;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.PolyNull;

import static android.content.Context.UI_MODE_SERVICE;

/**
* Miscellaneous utility methods.
Expand Down Expand Up @@ -1605,8 +1609,20 @@ public static String getStringForTime(StringBuilder builder, Formatter formatter
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();

if (hours == 0) {
if (minutes < 0) {
return formatter.format("%02d:%02d", minutes, seconds * -1).toString();
} else {
return formatter.format("%02d:%02d", minutes, seconds).toString();
}
} else {
if (hours < 0) {
return formatter.format("%d:%02d:%02d", hours, minutes * -1, seconds * -1).toString();
} else {
return formatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
}
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions library/dash/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply from: '../../constants.gradle'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
3 changes: 3 additions & 0 deletions library/hls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply from: '../../constants.gradle'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
3 changes: 3 additions & 0 deletions library/smoothstreaming/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply from: '../../constants.gradle'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
3 changes: 3 additions & 0 deletions library/ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
apply from: '../../constants.gradle'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.DiceTechnology'

android {
compileSdkVersion project.ext.compileSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.DvrMiddleware;
import com.google.android.exoplayer2.util.RepeatModeUtil;
import com.google.android.exoplayer2.util.Util;
import java.util.Arrays;
Expand Down Expand Up @@ -960,7 +961,7 @@ private void updateTimeline() {
}
long durationMs = C.usToMs(durationUs);
if (durationView != null) {
durationView.setText(Util.getStringForTime(formatBuilder, formatter, durationMs));
durationView.setText(Util.getStringForTime(formatBuilder, formatter, player.getEndPosition()));
}
if (timeBar != null) {
timeBar.setDuration(durationMs);
Expand Down Expand Up @@ -990,7 +991,7 @@ private void updateProgress() {
bufferedPosition = currentWindowOffset + player.getContentBufferedPosition();
}
if (positionView != null && !scrubbing) {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, position));
positionView.setText(Util.getStringForTime(formatBuilder, formatter, player.getStartPosition()));
}
if (timeBar != null) {
timeBar.setPosition(position);
Expand Down Expand Up @@ -1256,22 +1257,34 @@ private final class ComponentListener
public void onScrubStart(TimeBar timeBar, long position) {
scrubbing = true;
if (positionView != null) {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, position));
if (player.isCurrentWindowLive()) {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, DvrMiddleware.convertToNegativePosition(position, player.getDuration())));
} else {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, position));
}
}
}

@Override
public void onScrubMove(TimeBar timeBar, long position) {
if (positionView != null) {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, position));
if (player.isCurrentWindowLive()) {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, DvrMiddleware.convertToNegativePosition(position, player.getDuration())));
} else {
positionView.setText(Util.getStringForTime(formatBuilder, formatter, position));
}
}
}

@Override
public void onScrubStop(TimeBar timeBar, long position, boolean canceled) {
scrubbing = false;
if (!canceled && player != null) {
seekToTimeBarPosition(player, position);
if (player.isCurrentWindowLive()) {
seekToTimeBarPosition(player, DvrMiddleware.convertToNegativePosition(position, player.getDuration()));
} else {
seekToTimeBarPosition(player, position);
}
}
}

Expand Down

0 comments on commit 9c46c75

Please sign in to comment.