Skip to content

Commit

Permalink
Fix ImaAdsMediaSource isTopLevelSource
Browse files Browse the repository at this point in the history
AdsMediaSource must be top-level. Currently the (deprecated) ImaAdsMediaSource
can't be used because it prepares its contained AdsMediaSource as a child
source.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=186990882
  • Loading branch information
andrewlewis authored and ojw28 committed Mar 7, 2018
1 parent 052de3c commit 452e4de
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
import android.view.ViewGroup;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.CompositeMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource;
import java.io.IOException;

/**
* A {@link MediaSource} that inserts ads linearly with a provided content media source.
*
* @deprecated Use com.google.android.exoplayer2.source.ads.AdsMediaSource with ImaAdsLoader.
*/
@Deprecated
public final class ImaAdsMediaSource extends CompositeMediaSource<Void> {
public final class ImaAdsMediaSource implements MediaSource {

private final AdsMediaSource adsMediaSource;
private Listener listener;

/**
* Constructs a new source that inserts ads linearly with the content specified by
Expand Down Expand Up @@ -75,10 +74,23 @@ public ImaAdsMediaSource(
}

@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
super.prepareSource(player, isTopLevelSource, listener);
this.listener = listener;
prepareChildSource(/* id= */ null, adsMediaSource);
public void prepareSource(
final ExoPlayer player, boolean isTopLevelSource, final Listener listener) {
adsMediaSource.prepareSource(
player,
isTopLevelSource,
new Listener() {
@Override
public void onSourceInfoRefreshed(
MediaSource source, Timeline timeline, @Nullable Object manifest) {
listener.onSourceInfoRefreshed(ImaAdsMediaSource.this, timeline, manifest);
}
});
}

@Override
public void maybeThrowSourceInfoRefreshError() throws IOException {
adsMediaSource.maybeThrowSourceInfoRefreshError();
}

@Override
Expand All @@ -92,8 +104,7 @@ public void releasePeriod(MediaPeriod mediaPeriod) {
}

@Override
protected void onChildSourceInfoRefreshed(
Void id, MediaSource mediaSource, Timeline timeline, @Nullable Object manifest) {
listener.onSourceInfoRefreshed(this, timeline, manifest);
public void releaseSource() {
adsMediaSource.releaseSource();
}
}

0 comments on commit 452e4de

Please sign in to comment.