Skip to content

Commit

Permalink
Hack To Set windowDefaultStartPositionUs
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbenprimke committed Sep 3, 2019
1 parent 85c10b0 commit 4edd5cf
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
Expand Up @@ -462,6 +462,12 @@ private MediaSource buildMediaSource(Uri uri, @Nullable String overrideExtension
if (downloadRequest != null) {
return DownloadHelper.createMediaSource(downloadRequest, dataSourceFactory);
}
long defaultStartPositionUs = C.TIME_UNSET;
if (uri.getEncodedPath().contains("dizzy")) {
defaultStartPositionUs = C.msToUs(20000);
} else if (uri.getEncodedPath().contains("android-screens")) {
defaultStartPositionUs = C.msToUs(16000);
}
@ContentType int type = Util.inferContentType(uri, overrideExtension);
switch (type) {
case C.TYPE_DASH:
Expand All @@ -471,7 +477,9 @@ private MediaSource buildMediaSource(Uri uri, @Nullable String overrideExtension
case C.TYPE_HLS:
return new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
case C.TYPE_OTHER:
return new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
return new ProgressiveMediaSource
.Factory(dataSourceFactory)
.createMediaSource(uri, defaultStartPositionUs);
default:
throw new IllegalStateException("Unsupported type: " + type);
}
Expand Down
Expand Up @@ -419,6 +419,10 @@ private static MediaPeriod createMediaPeriod(
mediaPeriod =
new ClippingMediaPeriod(
mediaPeriod, /* enableInitialDiscontinuity= */ true, /* startUs= */ 0, endPositionUs);
} else if (startPositionUs != C.TIME_UNSET) {
mediaPeriod =
new ClippingMediaPeriod(
mediaPeriod, /* enableInitialDiscontinuity= */ true, /* startUs= */ startPositionUs, C.TIME_END_OF_SOURCE);
}
return mediaPeriod;
}
Expand Down
Expand Up @@ -179,6 +179,19 @@ public ProgressiveMediaSource createMediaSource(Uri uri) {
tag);
}

public ProgressiveMediaSource createMediaSource(Uri uri, long defaultStartPositionUs) {
isCreateCalled = true;
return new ProgressiveMediaSource(
uri,
dataSourceFactory,
extractorsFactory,
loadErrorHandlingPolicy,
customCacheKey,
continueLoadingCheckIntervalBytes,
defaultStartPositionUs,
tag);
}

@Override
public int[] getSupportedTypes() {
return new int[] {C.TYPE_OTHER};
Expand All @@ -201,9 +214,30 @@ public int[] getSupportedTypes() {

private long timelineDurationUs;
private boolean timelineIsSeekable;
private long defaultStartPositionUs;
@Nullable private TransferListener transferListener;

// TODO: Make private when ExtractorMediaSource is deleted.
/* package */ ProgressiveMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
@Nullable String customCacheKey,
int continueLoadingCheckIntervalBytes,
long defaultStartPositionUs,
@Nullable Object tag) {
this.uri = uri;
this.dataSourceFactory = dataSourceFactory;
this.extractorsFactory = extractorsFactory;
this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
this.customCacheKey = customCacheKey;
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
this.timelineDurationUs = C.TIME_UNSET;
this.defaultStartPositionUs = defaultStartPositionUs;
this.tag = tag;
}

/* package */ ProgressiveMediaSource(
Uri uri,
DataSource.Factory dataSourceFactory,
Expand All @@ -219,6 +253,7 @@ public int[] getSupportedTypes() {
this.customCacheKey = customCacheKey;
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
this.timelineDurationUs = C.TIME_UNSET;
this.defaultStartPositionUs = C.TIME_UNSET;
this.tag = tag;
}

Expand Down Expand Up @@ -288,7 +323,11 @@ private void notifySourceInfoRefreshed(long durationUs, boolean isSeekable) {
// TODO: Make timeline dynamic until its duration is known. This is non-trivial. See b/69703223.
refreshSourceInfo(
new SinglePeriodTimeline(
timelineDurationUs, timelineIsSeekable, /* isDynamic= */ false, tag),
timelineDurationUs,
defaultStartPositionUs == C.TIME_UNSET ? 0 : defaultStartPositionUs,
timelineIsSeekable,
/* isDynamic= */ false,
tag),
/* manifest= */ null);
}
}
Expand Up @@ -68,6 +68,18 @@ public SinglePeriodTimeline(
tag);
}

public SinglePeriodTimeline(
long durationUs, long windowDefaultStartPositionUs, boolean isSeekable, boolean isDynamic, @Nullable Object tag) {
this(
durationUs,
durationUs,
/* windowPositionInPeriodUs= */0,
/* windowDefaultStartPositionUs= */ windowDefaultStartPositionUs,
isSeekable,
isDynamic,
tag);
}

/**
* Creates a timeline with one period, and a window of known duration starting at a specified
* position in the period.
Expand Down
Binary file added windowDefaultStartPositionExample.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4edd5cf

Please sign in to comment.