mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove deprecated ImaAdsMediaSource and constructors
Given the change to require setPlayer on AdsLoaders, it seems like a good opportunity to clean up deprecated ads-related symbols. PiperOrigin-RevId: 233020171
This commit is contained in:
parent
2e9ef8abeb
commit
c16af73717
3 changed files with 9 additions and 285 deletions
|
|
@ -1,115 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.exoplayer2.ext.ima;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import com.google.android.exoplayer2.Timeline;
|
|
||||||
import com.google.android.exoplayer2.source.BaseMediaSource;
|
|
||||||
import com.google.android.exoplayer2.source.MediaPeriod;
|
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
|
||||||
import com.google.android.exoplayer2.source.MediaSource.SourceInfoRefreshListener;
|
|
||||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
|
||||||
import com.google.android.exoplayer2.upstream.Allocator;
|
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link MediaSource} that inserts ads linearly with a provided content media source.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link com.google.android.exoplayer2.source.ads.AdsMediaSource} with
|
|
||||||
* ImaAdsLoader.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public final class ImaAdsMediaSource extends BaseMediaSource implements SourceInfoRefreshListener {
|
|
||||||
|
|
||||||
private final AdsMediaSource adsMediaSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new source that inserts ads linearly with the content specified by
|
|
||||||
* {@code contentMediaSource}.
|
|
||||||
*
|
|
||||||
* @param contentMediaSource The {@link MediaSource} providing the content to play.
|
|
||||||
* @param dataSourceFactory Factory for data sources used to load ad media.
|
|
||||||
* @param imaAdsLoader The loader for ads.
|
|
||||||
* @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
|
|
||||||
*/
|
|
||||||
public ImaAdsMediaSource(MediaSource contentMediaSource, DataSource.Factory dataSourceFactory,
|
|
||||||
ImaAdsLoader imaAdsLoader, ViewGroup adUiViewGroup) {
|
|
||||||
this(contentMediaSource, dataSourceFactory, imaAdsLoader, adUiViewGroup, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new source that inserts ads linearly with the content specified by {@code
|
|
||||||
* contentMediaSource}.
|
|
||||||
*
|
|
||||||
* @param contentMediaSource The {@link MediaSource} providing the content to play.
|
|
||||||
* @param dataSourceFactory Factory for data sources used to load ad media.
|
|
||||||
* @param imaAdsLoader The loader for ads.
|
|
||||||
* @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
|
|
||||||
* @param eventHandler A handler for events. May be null if delivery of events is not required.
|
|
||||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
|
||||||
*/
|
|
||||||
public ImaAdsMediaSource(
|
|
||||||
MediaSource contentMediaSource,
|
|
||||||
DataSource.Factory dataSourceFactory,
|
|
||||||
ImaAdsLoader imaAdsLoader,
|
|
||||||
ViewGroup adUiViewGroup,
|
|
||||||
@Nullable Handler eventHandler,
|
|
||||||
@Nullable AdsMediaSource.EventListener eventListener) {
|
|
||||||
adsMediaSource = new AdsMediaSource(contentMediaSource, dataSourceFactory, imaAdsLoader,
|
|
||||||
adUiViewGroup, eventHandler, eventListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public Object getTag() {
|
|
||||||
return adsMediaSource.getTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
|
|
||||||
adsMediaSource.prepareSource(/* listener= */ this, mediaTransferListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
|
||||||
adsMediaSource.maybeThrowSourceInfoRefreshError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
|
|
||||||
return adsMediaSource.createPeriod(id, allocator, startPositionUs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
|
||||||
adsMediaSource.releasePeriod(mediaPeriod);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void releaseSourceInternal() {
|
|
||||||
adsMediaSource.releaseSource(/* listener= */ this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSourceInfoRefreshed(
|
|
||||||
MediaSource source, Timeline timeline, @Nullable Object manifest) {
|
|
||||||
refreshSourceInfo(timeline, manifest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -26,7 +26,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Interface for loaders of ads, which can be used with {@link AdsMediaSource}.
|
* Interface for loaders of ads, which can be used with {@link AdsMediaSource}.
|
||||||
*
|
*
|
||||||
* <p>Ad loaders notify the {@link AdsMediaSource} about events via {@link EventListener}. In
|
* <p>Ads loaders notify the {@link AdsMediaSource} about events via {@link EventListener}. In
|
||||||
* particular, implementations must call {@link EventListener#onAdPlaybackState(AdPlaybackState)}
|
* particular, implementations must call {@link EventListener#onAdPlaybackState(AdPlaybackState)}
|
||||||
* with a new copy of the current {@link AdPlaybackState} whenever further information about ads
|
* with a new copy of the current {@link AdPlaybackState} whenever further information about ads
|
||||||
* becomes known (for example, when an ad media URI is available, or an ad has played to the end).
|
* becomes known (for example, when an ad media URI is available, or an ad has played to the end).
|
||||||
|
|
@ -44,9 +44,7 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public interface AdsLoader {
|
public interface AdsLoader {
|
||||||
|
|
||||||
/**
|
/** Listener for ads loader events. All methods are called on the main thread. */
|
||||||
* Listener for ad loader events. All methods are called on the main thread.
|
|
||||||
*/
|
|
||||||
interface EventListener {
|
interface EventListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,7 +52,7 @@ public interface AdsLoader {
|
||||||
*
|
*
|
||||||
* @param adPlaybackState The new ad playback state.
|
* @param adPlaybackState The new ad playback state.
|
||||||
*/
|
*/
|
||||||
void onAdPlaybackState(AdPlaybackState adPlaybackState);
|
default void onAdPlaybackState(AdPlaybackState adPlaybackState) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when there was an error loading ads.
|
* Called when there was an error loading ads.
|
||||||
|
|
@ -62,18 +60,13 @@ public interface AdsLoader {
|
||||||
* @param error The error.
|
* @param error The error.
|
||||||
* @param dataSpec The data spec associated with the load error.
|
* @param dataSpec The data spec associated with the load error.
|
||||||
*/
|
*/
|
||||||
void onAdLoadError(AdLoadException error, DataSpec dataSpec);
|
default void onAdLoadError(AdLoadException error, DataSpec dataSpec) {}
|
||||||
|
|
||||||
/**
|
/** Called when the user clicks through an ad (for example, following a 'learn more' link). */
|
||||||
* Called when the user clicks through an ad (for example, following a 'learn more' link).
|
default void onAdClicked() {}
|
||||||
*/
|
|
||||||
void onAdClicked();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user taps a non-clickthrough part of an ad.
|
|
||||||
*/
|
|
||||||
void onAdTapped();
|
|
||||||
|
|
||||||
|
/** Called when the user taps a non-clickthrough part of an ad. */
|
||||||
|
default void onAdTapped() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods called by the application.
|
// Methods called by the application.
|
||||||
|
|
|
||||||
|
|
@ -139,46 +139,6 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Listener for ads media source events.
|
|
||||||
*
|
|
||||||
* @deprecated To listen for ad load error events, add a listener via {@link
|
|
||||||
* #addEventListener(Handler, MediaSourceEventListener)} and check for {@link
|
|
||||||
* AdLoadException}s in {@link MediaSourceEventListener#onLoadError(int, MediaPeriodId,
|
|
||||||
* LoadEventInfo, MediaLoadData, IOException, boolean)}. Individual ads loader implementations
|
|
||||||
* should expose ad interaction events, if applicable.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface EventListener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called if there was an error loading one or more ads. The loader will skip the problematic
|
|
||||||
* ad(s).
|
|
||||||
*
|
|
||||||
* @param error The error.
|
|
||||||
*/
|
|
||||||
void onAdLoadError(IOException error);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an unexpected internal error is encountered while loading ads. The loader will
|
|
||||||
* skip all remaining ads, as the error is not recoverable.
|
|
||||||
*
|
|
||||||
* @param error The error.
|
|
||||||
*/
|
|
||||||
void onInternalAdLoadError(RuntimeException error);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user clicks through an ad (for example, following a 'learn more' link).
|
|
||||||
*/
|
|
||||||
void onAdClicked();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user taps a non-clickthrough part of an ad.
|
|
||||||
*/
|
|
||||||
void onAdTapped();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to identify the content "child" source for CompositeMediaSource.
|
// Used to identify the content "child" source for CompositeMediaSource.
|
||||||
private static final MediaPeriodId DUMMY_CONTENT_MEDIA_PERIOD_ID =
|
private static final MediaPeriodId DUMMY_CONTENT_MEDIA_PERIOD_ID =
|
||||||
new MediaPeriodId(/* periodUid= */ new Object());
|
new MediaPeriodId(/* periodUid= */ new Object());
|
||||||
|
|
@ -187,8 +147,6 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
private final MediaSourceFactory adMediaSourceFactory;
|
private final MediaSourceFactory adMediaSourceFactory;
|
||||||
private final AdsLoader adsLoader;
|
private final AdsLoader adsLoader;
|
||||||
private final ViewGroup adUiViewGroup;
|
private final ViewGroup adUiViewGroup;
|
||||||
@Nullable private final Handler eventHandler;
|
|
||||||
@Nullable private final EventListener eventListener;
|
|
||||||
private final Handler mainHandler;
|
private final Handler mainHandler;
|
||||||
private final Map<MediaSource, List<DeferredMediaPeriod>> deferredMediaPeriodByAdMediaSource;
|
private final Map<MediaSource, List<DeferredMediaPeriod>> deferredMediaPeriodByAdMediaSource;
|
||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
|
|
@ -219,9 +177,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
contentMediaSource,
|
contentMediaSource,
|
||||||
new ExtractorMediaSource.Factory(dataSourceFactory),
|
new ExtractorMediaSource.Factory(dataSourceFactory),
|
||||||
adsLoader,
|
adsLoader,
|
||||||
adUiViewGroup,
|
adUiViewGroup);
|
||||||
/* eventHandler= */ null,
|
|
||||||
/* eventListener= */ null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -238,78 +194,10 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
MediaSourceFactory adMediaSourceFactory,
|
MediaSourceFactory adMediaSourceFactory,
|
||||||
AdsLoader adsLoader,
|
AdsLoader adsLoader,
|
||||||
ViewGroup adUiViewGroup) {
|
ViewGroup adUiViewGroup) {
|
||||||
this(
|
|
||||||
contentMediaSource,
|
|
||||||
adMediaSourceFactory,
|
|
||||||
adsLoader,
|
|
||||||
adUiViewGroup,
|
|
||||||
/* eventHandler= */ null,
|
|
||||||
/* eventListener= */ null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new source that inserts ads linearly with the content specified by {@code
|
|
||||||
* contentMediaSource}. Ad media is loaded using {@link ExtractorMediaSource}.
|
|
||||||
*
|
|
||||||
* @param contentMediaSource The {@link MediaSource} providing the content to play.
|
|
||||||
* @param dataSourceFactory Factory for data sources used to load ad media.
|
|
||||||
* @param adsLoader The loader for ads.
|
|
||||||
* @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
|
|
||||||
* @param eventHandler A handler for events. May be null if delivery of events is not required.
|
|
||||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
|
||||||
* @deprecated To listen for ad load error events, add a listener via {@link
|
|
||||||
* #addEventListener(Handler, MediaSourceEventListener)} and check for {@link
|
|
||||||
* AdLoadException}s in {@link MediaSourceEventListener#onLoadError(int, MediaPeriodId,
|
|
||||||
* LoadEventInfo, MediaLoadData, IOException, boolean)}. Individual ads loader implementations
|
|
||||||
* should expose ad interaction events, if applicable.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public AdsMediaSource(
|
|
||||||
MediaSource contentMediaSource,
|
|
||||||
DataSource.Factory dataSourceFactory,
|
|
||||||
AdsLoader adsLoader,
|
|
||||||
ViewGroup adUiViewGroup,
|
|
||||||
@Nullable Handler eventHandler,
|
|
||||||
@Nullable EventListener eventListener) {
|
|
||||||
this(
|
|
||||||
contentMediaSource,
|
|
||||||
new ExtractorMediaSource.Factory(dataSourceFactory),
|
|
||||||
adsLoader,
|
|
||||||
adUiViewGroup,
|
|
||||||
eventHandler,
|
|
||||||
eventListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new source that inserts ads linearly with the content specified by {@code
|
|
||||||
* contentMediaSource}.
|
|
||||||
*
|
|
||||||
* @param contentMediaSource The {@link MediaSource} providing the content to play.
|
|
||||||
* @param adMediaSourceFactory Factory for media sources used to load ad media.
|
|
||||||
* @param adsLoader The loader for ads.
|
|
||||||
* @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
|
|
||||||
* @param eventHandler A handler for events. May be null if delivery of events is not required.
|
|
||||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
|
||||||
* @deprecated To listen for ad load error events, add a listener via {@link
|
|
||||||
* #addEventListener(Handler, MediaSourceEventListener)} and check for {@link
|
|
||||||
* AdLoadException}s in {@link MediaSourceEventListener#onLoadError(int, MediaPeriodId,
|
|
||||||
* LoadEventInfo, MediaLoadData, IOException, boolean)}. Individual ads loader implementations
|
|
||||||
* should expose ad interaction events, if applicable.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public AdsMediaSource(
|
|
||||||
MediaSource contentMediaSource,
|
|
||||||
MediaSourceFactory adMediaSourceFactory,
|
|
||||||
AdsLoader adsLoader,
|
|
||||||
ViewGroup adUiViewGroup,
|
|
||||||
@Nullable Handler eventHandler,
|
|
||||||
@Nullable EventListener eventListener) {
|
|
||||||
this.contentMediaSource = contentMediaSource;
|
this.contentMediaSource = contentMediaSource;
|
||||||
this.adMediaSourceFactory = adMediaSourceFactory;
|
this.adMediaSourceFactory = adMediaSourceFactory;
|
||||||
this.adsLoader = adsLoader;
|
this.adsLoader = adsLoader;
|
||||||
this.adUiViewGroup = adUiViewGroup;
|
this.adUiViewGroup = adUiViewGroup;
|
||||||
this.eventHandler = eventHandler;
|
|
||||||
this.eventListener = eventListener;
|
|
||||||
mainHandler = new Handler(Looper.getMainLooper());
|
mainHandler = new Handler(Looper.getMainLooper());
|
||||||
deferredMediaPeriodByAdMediaSource = new HashMap<>();
|
deferredMediaPeriodByAdMediaSource = new HashMap<>();
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
|
|
@ -522,36 +410,6 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdClicked() {
|
|
||||||
if (released) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (eventHandler != null && eventListener != null) {
|
|
||||||
eventHandler.post(
|
|
||||||
() -> {
|
|
||||||
if (!released) {
|
|
||||||
eventListener.onAdClicked();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdTapped() {
|
|
||||||
if (released) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (eventHandler != null && eventListener != null) {
|
|
||||||
eventHandler.post(
|
|
||||||
() -> {
|
|
||||||
if (!released) {
|
|
||||||
eventListener.onAdTapped();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdLoadError(final AdLoadException error, DataSpec dataSpec) {
|
public void onAdLoadError(final AdLoadException error, DataSpec dataSpec) {
|
||||||
if (released) {
|
if (released) {
|
||||||
|
|
@ -568,18 +426,6 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
|
||||||
/* bytesLoaded= */ 0,
|
/* bytesLoaded= */ 0,
|
||||||
error,
|
error,
|
||||||
/* wasCanceled= */ true);
|
/* wasCanceled= */ true);
|
||||||
if (eventHandler != null && eventListener != null) {
|
|
||||||
eventHandler.post(
|
|
||||||
() -> {
|
|
||||||
if (!released) {
|
|
||||||
if (error.type == AdLoadException.TYPE_UNEXPECTED) {
|
|
||||||
eventListener.onInternalAdLoadError(error.getRuntimeExceptionForUnexpected());
|
|
||||||
} else {
|
|
||||||
eventListener.onAdLoadError(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue