Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MediaSource): client code can get the tag of a MediaSource #5187

Merged
merged 3 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public ImaAdsMediaSource(
adUiViewGroup, eventHandler, eventListener);
}

@Override
@Nullable
public Object getTag() {
return adsMediaSource.getTag();
}

@Override
public void prepareSourceInternal(
final ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ public ClippingMediaSource(
window = new Timeline.Window();
}

@Override
@Nullable
public Object getTag() {
return mediaSource.getTag();
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ public final synchronized void setShuffleOrder(
}
}

@Override
@Nullable
public Object getTag() {
return null;
}

@Override
public final synchronized void prepareSourceInternal(
ExoPlayer player,
Expand Down Expand Up @@ -1069,6 +1075,12 @@ protected void prepareSourceInternal(
// Do nothing.
}

@Override
@Nullable
public Object getTag() {
return null;
}

@Override
protected void releaseSourceInternal() {
// Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ private ExtractorMediaSource(
this.tag = tag;
}

@Override
@Nullable
public Object getTag() {
return tag;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public LoopingMediaSource(MediaSource childSource, int loopCount) {
mediaPeriodToChildMediaPeriodId = new HashMap<>();
}

@Override
@Nullable
public Object getTag() {
return childSource.getTag();
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ public int hashCode() {
*/
void removeEventListener(MediaSourceEventListener eventListener);

/**
* Returns the tag set on the media source, or null when none was set.
*/
@Nullable default Object getTag() {
return null;
}

/**
* Starts source preparation if not yet started, and adds a listener for timeline and/or manifest
* updates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public MergingMediaSource(CompositeSequenceableLoaderFactory compositeSequenceab
timelines = new Timeline[mediaSources.length];
}

@Override
@Nullable
public Object getTag() {
return mediaSources.length > 0 ? mediaSources[0].getTag() : null;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public SingleSampleMediaSource createMediaSource(
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private final boolean treatLoadErrorsAsEndOfStream;
private final Timeline timeline;
private final @Nullable Object tag;

private @Nullable TransferListener transferListener;

Expand Down Expand Up @@ -287,6 +288,7 @@ private SingleSampleMediaSource(
this.durationUs = durationUs;
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
this.tag = tag;
dataSpec =
new DataSpec(uri, DataSpec.FLAG_ALLOW_GZIP | DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH);
timeline =
Expand All @@ -295,6 +297,12 @@ private SingleSampleMediaSource(

// MediaSource implementation.

@Override
@Nullable
public Object getTag() {
return tag;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ public AdsMediaSource(
adsLoader.setSupportedContentTypes(adMediaSourceFactory.getSupportedTypes());
}

@Override
@Nullable
public Object getTag() {
return contentMediaSource.getTag();
}

@Override
public void prepareSourceInternal(
final ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@ public void replaceManifestUri(Uri manifestUri) {

// MediaSource implementation.

@Override
@Nullable
public Object getTag() {
return tag;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ private HlsMediaSource(
this.tag = tag;
}

@Override
@Nullable
public Object getTag() {
return tag;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ private SsMediaSource(

// MediaSource implementation.

@Override
@Nullable
public Object getTag() {
return tag;
}

@Override
public void prepareSourceInternal(
ExoPlayer player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public FakeMediaSource(@Nullable Timeline timeline, Object manifest,
this.trackGroupArray = trackGroupArray;
}

@Override
@Nullable
public Object getTag() {
boolean hasTimeline = timeline != null && !timeline.isEmpty();

return hasTimeline ? timeline.getWindow(0, new Timeline.Window()).tag : null;
}

@Override
public synchronized void prepareSourceInternal(
ExoPlayer player,
Expand Down