Commit e8293b92 by bachinger Committed by kim-vde

remove deprecated usage of onPlayerStateChanged in ImaAdsLoader

PiperOrigin-RevId: 293612280
parent b69918a2
...@@ -332,7 +332,7 @@ public final class ImaAdsLoader ...@@ -332,7 +332,7 @@ public final class ImaAdsLoader
private VideoProgressUpdate lastAdProgress; private VideoProgressUpdate lastAdProgress;
private int lastVolumePercentage; private int lastVolumePercentage;
private AdsManager adsManager; @Nullable private AdsManager adsManager;
private boolean initializedAdsManager; private boolean initializedAdsManager;
private AdLoadException pendingAdLoadError; private AdLoadException pendingAdLoadError;
private Timeline timeline; private Timeline timeline;
...@@ -973,12 +973,21 @@ public final class ImaAdsLoader ...@@ -973,12 +973,21 @@ public final class ImaAdsLoader
initializedAdsManager = true; initializedAdsManager = true;
initializeAdsManager(); initializeAdsManager();
} }
onPositionDiscontinuity(Player.DISCONTINUITY_REASON_INTERNAL); checkForContentCompleteOrNewAdGroup();
} }
@Override @Override
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) { public void onPlaybackStateChanged(@Player.State int playbackState) {
if (adsManager == null) { if (adsManager == null || player == null) {
return;
}
handlePlayerStateChanged(player.getPlayWhenReady(), playbackState);
}
@Override
public void onPlayWhenReadyChanged(
boolean playWhenReady, @Player.PlayWhenReadyChangeReason int reason) {
if (adsManager == null || player == null) {
return; return;
} }
...@@ -991,18 +1000,7 @@ public final class ImaAdsLoader ...@@ -991,18 +1000,7 @@ public final class ImaAdsLoader
adsManager.resume(); adsManager.resume();
return; return;
} }
handlePlayerStateChanged(playWhenReady, player.getPlaybackState());
if (imaAdState == IMA_AD_STATE_NONE && playbackState == Player.STATE_BUFFERING
&& playWhenReady) {
checkForContentComplete();
} else if (imaAdState != IMA_AD_STATE_NONE && playbackState == Player.STATE_ENDED) {
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded();
}
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onPlayerStateChanged");
}
}
} }
@Override @Override
...@@ -1016,32 +1014,7 @@ public final class ImaAdsLoader ...@@ -1016,32 +1014,7 @@ public final class ImaAdsLoader
@Override @Override
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
if (adsManager == null) { checkForContentCompleteOrNewAdGroup();
return;
}
if (!playingAd && !player.isPlayingAd()) {
checkForContentComplete();
if (sentContentComplete) {
for (int i = 0; i < adPlaybackState.adGroupCount; i++) {
if (adPlaybackState.adGroupTimesUs[i] != C.TIME_END_OF_SOURCE) {
adPlaybackState = adPlaybackState.withSkippedAdGroup(i);
}
}
updateAdPlaybackState();
} else if (!timeline.isEmpty()) {
long positionMs = player.getCurrentPosition();
timeline.getPeriod(0, period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(C.msToUs(positionMs));
if (newAdGroupIndex != C.INDEX_UNSET) {
sentPendingContentPositionMs = false;
pendingContentPositionMs = positionMs;
if (newAdGroupIndex != adGroupIndex) {
shouldNotifyAdPrepareError = false;
}
}
}
}
updateImaStateForPlayerState();
} }
// Internal methods. // Internal methods.
...@@ -1174,6 +1147,50 @@ public final class ImaAdsLoader ...@@ -1174,6 +1147,50 @@ public final class ImaAdsLoader
} }
} }
private void handlePlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
if (imaAdState == IMA_AD_STATE_NONE
&& playbackState == Player.STATE_BUFFERING
&& playWhenReady) {
checkForContentComplete();
} else if (imaAdState != IMA_AD_STATE_NONE && playbackState == Player.STATE_ENDED) {
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded();
}
if (DEBUG) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onPlaybackStateChanged");
}
}
}
private void checkForContentCompleteOrNewAdGroup() {
if (adsManager == null || player == null) {
return;
}
if (!playingAd && !player.isPlayingAd()) {
checkForContentComplete();
if (sentContentComplete) {
for (int i = 0; i < adPlaybackState.adGroupCount; i++) {
if (adPlaybackState.adGroupTimesUs[i] != C.TIME_END_OF_SOURCE) {
adPlaybackState = adPlaybackState.withSkippedAdGroup(/* adGroupIndex= */ i);
}
}
updateAdPlaybackState();
} else if (!timeline.isEmpty()) {
long positionMs = player.getCurrentPosition();
timeline.getPeriod(/* periodIndex= */ 0, period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(C.msToUs(positionMs));
if (newAdGroupIndex != C.INDEX_UNSET) {
sentPendingContentPositionMs = false;
pendingContentPositionMs = positionMs;
if (newAdGroupIndex != adGroupIndex) {
shouldNotifyAdPrepareError = false;
}
}
}
}
updateImaStateForPlayerState();
}
private void updateImaStateForPlayerState() { private void updateImaStateForPlayerState() {
boolean wasPlayingAd = playingAd; boolean wasPlayingAd = playingAd;
int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup; int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment