mirror of
https://github.com/androidx/media.git
synced 2025-05-11 09:39:52 +08:00
Fix ImaAdsMediaSource isTopLevelSource
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
This commit is contained in:
parent
f2f5aac7c5
commit
c4f82514bf
@ -20,12 +20,12 @@ import android.support.annotation.Nullable;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
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.MediaPeriod;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
||||||
import com.google.android.exoplayer2.upstream.Allocator;
|
import com.google.android.exoplayer2.upstream.Allocator;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MediaSource} that inserts ads linearly with a provided content media source.
|
* A {@link MediaSource} that inserts ads linearly with a provided content media source.
|
||||||
@ -33,10 +33,9 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
|||||||
* @deprecated Use com.google.android.exoplayer2.source.ads.AdsMediaSource with ImaAdsLoader.
|
* @deprecated Use com.google.android.exoplayer2.source.ads.AdsMediaSource with ImaAdsLoader.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final class ImaAdsMediaSource extends CompositeMediaSource<Void> {
|
public final class ImaAdsMediaSource implements MediaSource {
|
||||||
|
|
||||||
private final AdsMediaSource adsMediaSource;
|
private final AdsMediaSource adsMediaSource;
|
||||||
private Listener listener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new source that inserts ads linearly with the content specified by
|
* Constructs a new source that inserts ads linearly with the content specified by
|
||||||
@ -75,10 +74,23 @@ public final class ImaAdsMediaSource extends CompositeMediaSource<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
public void prepareSource(
|
||||||
super.prepareSource(player, isTopLevelSource, listener);
|
final ExoPlayer player, boolean isTopLevelSource, final Listener listener) {
|
||||||
this.listener = listener;
|
adsMediaSource.prepareSource(
|
||||||
prepareChildSource(/* id= */ null, adsMediaSource);
|
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
|
@Override
|
||||||
@ -92,8 +104,7 @@ public final class ImaAdsMediaSource extends CompositeMediaSource<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onChildSourceInfoRefreshed(
|
public void releaseSource() {
|
||||||
Void id, MediaSource mediaSource, Timeline timeline, @Nullable Object manifest) {
|
adsMediaSource.releaseSource();
|
||||||
listener.onSourceInfoRefreshed(this, timeline, manifest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user