mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
Fix handling of delayed AdsLoader.start
AdsMediaSource posts AdsLoader.start to the main thread during preparation, but the app may call AdsLoader.setPlayer(null) before it actually runs (e.g., if initializing then quickly backgrounding the player). This is valid usage of the API so handle this case instead of asserting. Because not calling setPlayer at all is a pitfall of the API, track whether setPlayer has been called and still assert that in AdsLoader.start. PiperOrigin-RevId: 264329632
This commit is contained in:
parent
ebf8dc9973
commit
c361e3abc3
@ -327,6 +327,7 @@ public final class ImaAdsLoader
|
||||
private final AdDisplayContainer adDisplayContainer;
|
||||
private final com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader;
|
||||
|
||||
private boolean wasSetPlayerCalled;
|
||||
@Nullable private Player nextPlayer;
|
||||
private Object pendingAdRequestContext;
|
||||
private List<String> supportedMimeTypes;
|
||||
@ -558,6 +559,7 @@ public final class ImaAdsLoader
|
||||
Assertions.checkState(
|
||||
player == null || player.getApplicationLooper() == Looper.getMainLooper());
|
||||
nextPlayer = player;
|
||||
wasSetPlayerCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -585,9 +587,12 @@ public final class ImaAdsLoader
|
||||
|
||||
@Override
|
||||
public void start(EventListener eventListener, AdViewProvider adViewProvider) {
|
||||
Assertions.checkNotNull(
|
||||
nextPlayer, "Set player using adsLoader.setPlayer before preparing the player.");
|
||||
Assertions.checkState(
|
||||
wasSetPlayerCalled, "Set player using adsLoader.setPlayer before preparing the player.");
|
||||
player = nextPlayer;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
this.eventListener = eventListener;
|
||||
lastVolumePercentage = 0;
|
||||
lastAdProgress = null;
|
||||
@ -617,6 +622,9 @@ public final class ImaAdsLoader
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (adsManager != null && imaPausedContent) {
|
||||
adPlaybackState =
|
||||
adPlaybackState.withAdResumePositionUs(
|
||||
|
Loading…
x
Reference in New Issue
Block a user