mirror of
https://github.com/androidx/media.git
synced 2025-05-09 08:30:43 +08:00
remove deprecated usage of onPlayerStateChanged in ImaAdsLoader
PiperOrigin-RevId: 293612280
This commit is contained in:
parent
b69918a21e
commit
e8293b92d8
@ -332,7 +332,7 @@ public final class ImaAdsLoader
|
||||
private VideoProgressUpdate lastAdProgress;
|
||||
private int lastVolumePercentage;
|
||||
|
||||
private AdsManager adsManager;
|
||||
@Nullable private AdsManager adsManager;
|
||||
private boolean initializedAdsManager;
|
||||
private AdLoadException pendingAdLoadError;
|
||||
private Timeline timeline;
|
||||
@ -973,12 +973,21 @@ public final class ImaAdsLoader
|
||||
initializedAdsManager = true;
|
||||
initializeAdsManager();
|
||||
}
|
||||
onPositionDiscontinuity(Player.DISCONTINUITY_REASON_INTERNAL);
|
||||
checkForContentCompleteOrNewAdGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (adsManager == null) {
|
||||
public void onPlaybackStateChanged(@Player.State int playbackState) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -991,18 +1000,7 @@ public final class ImaAdsLoader
|
||||
adsManager.resume();
|
||||
return;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
handlePlayerStateChanged(playWhenReady, player.getPlaybackState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1016,32 +1014,7 @@ public final class ImaAdsLoader
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
|
||||
if (adsManager == 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(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();
|
||||
checkForContentCompleteOrNewAdGroup();
|
||||
}
|
||||
|
||||
// Internal methods.
|
||||
@ -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() {
|
||||
boolean wasPlayingAd = playingAd;
|
||||
int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup;
|
||||
|
Loading…
x
Reference in New Issue
Block a user