mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Minor cleanup to separate content progress provider interface
PiperOrigin-RevId: 740901722
This commit is contained in:
parent
87e0d7b95a
commit
10fd1ee270
@ -143,6 +143,8 @@ import java.util.Objects;
|
|||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final ComponentListener componentListener;
|
private final ComponentListener componentListener;
|
||||||
|
private final ContentPlaybackAdapter contentPlaybackAdapter;
|
||||||
|
private final VideoAdPlayerImpl videoAdPlayerImpl;
|
||||||
private final List<EventListener> eventListeners;
|
private final List<EventListener> eventListeners;
|
||||||
private final List<VideoAdPlayer.VideoAdPlayerCallback> adCallbacks;
|
private final List<VideoAdPlayer.VideoAdPlayerCallback> adCallbacks;
|
||||||
private final Runnable updateAdProgressRunnable;
|
private final Runnable updateAdProgressRunnable;
|
||||||
@ -262,6 +264,8 @@ import java.util.Objects;
|
|||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
handler = Util.createHandler(getImaLooper(), /* callback= */ null);
|
handler = Util.createHandler(getImaLooper(), /* callback= */ null);
|
||||||
componentListener = new ComponentListener();
|
componentListener = new ComponentListener();
|
||||||
|
contentPlaybackAdapter = new ContentPlaybackAdapter();
|
||||||
|
videoAdPlayerImpl = new VideoAdPlayerImpl();
|
||||||
eventListeners = new ArrayList<>();
|
eventListeners = new ArrayList<>();
|
||||||
adCallbacks = new ArrayList<>(/* initialCapacity= */ 1);
|
adCallbacks = new ArrayList<>(/* initialCapacity= */ 1);
|
||||||
if (configuration.applicationVideoAdPlayerCallback != null) {
|
if (configuration.applicationVideoAdPlayerCallback != null) {
|
||||||
@ -281,10 +285,10 @@ import java.util.Objects;
|
|||||||
adLoadTimeoutRunnable = this::handleAdLoadTimeout;
|
adLoadTimeoutRunnable = this::handleAdLoadTimeout;
|
||||||
if (adViewGroup != null) {
|
if (adViewGroup != null) {
|
||||||
adDisplayContainer =
|
adDisplayContainer =
|
||||||
imaFactory.createAdDisplayContainer(adViewGroup, /* player= */ componentListener);
|
imaFactory.createAdDisplayContainer(adViewGroup, /* player= */ videoAdPlayerImpl);
|
||||||
} else {
|
} else {
|
||||||
adDisplayContainer =
|
adDisplayContainer =
|
||||||
imaFactory.createAudioAdDisplayContainer(context, /* player= */ componentListener);
|
imaFactory.createAudioAdDisplayContainer(context, /* player= */ videoAdPlayerImpl);
|
||||||
}
|
}
|
||||||
if (configuration.companionAdSlots != null) {
|
if (configuration.companionAdSlots != null) {
|
||||||
adDisplayContainer.setCompanionSlots(configuration.companionAdSlots);
|
adDisplayContainer.setCompanionSlots(configuration.companionAdSlots);
|
||||||
@ -578,7 +582,7 @@ import java.util.Objects;
|
|||||||
if (configuration.vastLoadTimeoutMs != TIMEOUT_UNSET) {
|
if (configuration.vastLoadTimeoutMs != TIMEOUT_UNSET) {
|
||||||
request.setVastLoadTimeout(configuration.vastLoadTimeoutMs);
|
request.setVastLoadTimeout(configuration.vastLoadTimeoutMs);
|
||||||
}
|
}
|
||||||
request.setContentProgressProvider(componentListener);
|
request.setContentProgressProvider(contentPlaybackAdapter);
|
||||||
adsLoader.requestAds(request);
|
adsLoader.requestAds(request);
|
||||||
return adsLoader;
|
return adsLoader;
|
||||||
}
|
}
|
||||||
@ -1353,42 +1357,7 @@ import java.util.Objects;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class ComponentListener
|
private final class ContentPlaybackAdapter implements ContentProgressProvider {
|
||||||
implements AdsLoadedListener,
|
|
||||||
ContentProgressProvider,
|
|
||||||
AdEventListener,
|
|
||||||
AdErrorListener,
|
|
||||||
VideoAdPlayer {
|
|
||||||
|
|
||||||
// AdsLoader.AdsLoadedListener implementation.
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
|
|
||||||
AdsManager adsManager = adsManagerLoadedEvent.getAdsManager();
|
|
||||||
if (!Objects.equals(pendingAdRequestContext, adsManagerLoadedEvent.getUserRequestContext())) {
|
|
||||||
adsManager.destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pendingAdRequestContext = null;
|
|
||||||
AdTagLoader.this.adsManager = adsManager;
|
|
||||||
adsManager.addAdErrorListener(this);
|
|
||||||
if (configuration.applicationAdErrorListener != null) {
|
|
||||||
adsManager.addAdErrorListener(configuration.applicationAdErrorListener);
|
|
||||||
}
|
|
||||||
adsManager.addAdEventListener(this);
|
|
||||||
if (configuration.applicationAdEventListener != null) {
|
|
||||||
adsManager.addAdEventListener(configuration.applicationAdEventListener);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
adPlaybackState =
|
|
||||||
new AdPlaybackState(adsId, getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
|
|
||||||
updateAdPlaybackState();
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
maybeNotifyInternalError("onAdsManagerLoaded", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContentProgressProvider implementation.
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VideoProgressUpdate getContentProgress() {
|
public VideoProgressUpdate getContentProgress() {
|
||||||
@ -1419,6 +1388,38 @@ import java.util.Objects;
|
|||||||
|
|
||||||
return videoProgressUpdate;
|
return videoProgressUpdate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class ComponentListener
|
||||||
|
implements AdsLoadedListener, AdEventListener, AdErrorListener {
|
||||||
|
|
||||||
|
// AdsLoader.AdsLoadedListener implementation.
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
|
||||||
|
AdsManager adsManager = adsManagerLoadedEvent.getAdsManager();
|
||||||
|
if (!Objects.equals(pendingAdRequestContext, adsManagerLoadedEvent.getUserRequestContext())) {
|
||||||
|
adsManager.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pendingAdRequestContext = null;
|
||||||
|
AdTagLoader.this.adsManager = adsManager;
|
||||||
|
adsManager.addAdErrorListener(this);
|
||||||
|
if (configuration.applicationAdErrorListener != null) {
|
||||||
|
adsManager.addAdErrorListener(configuration.applicationAdErrorListener);
|
||||||
|
}
|
||||||
|
adsManager.addAdEventListener(this);
|
||||||
|
if (configuration.applicationAdEventListener != null) {
|
||||||
|
adsManager.addAdEventListener(configuration.applicationAdEventListener);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
adPlaybackState =
|
||||||
|
new AdPlaybackState(adsId, getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
|
||||||
|
updateAdPlaybackState();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
maybeNotifyInternalError("onAdsManagerLoaded", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AdEvent.AdEventListener implementation.
|
// AdEvent.AdEventListener implementation.
|
||||||
|
|
||||||
@ -1460,8 +1461,9 @@ import java.util.Objects;
|
|||||||
}
|
}
|
||||||
maybeNotifyPendingAdLoadError();
|
maybeNotifyPendingAdLoadError();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// VideoAdPlayer implementation.
|
class VideoAdPlayerImpl implements VideoAdPlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCallback(VideoAdPlayerCallback videoAdPlayerCallback) {
|
public void addCallback(VideoAdPlayerCallback videoAdPlayerCallback) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user