Commit 0c301fef by andrewlewis Committed by Andrew Lewis

Pass AdsMediaSource to other AdsLoader methods

Issue: #3750
PiperOrigin-RevId: 341020676
parent d94943f0
...@@ -494,7 +494,7 @@ public final class ImaAdsLoader ...@@ -494,7 +494,7 @@ public final class ImaAdsLoader
} }
@Override @Override
public void stop() { public void stop(AdsMediaSource adsMediaSource) {
if (player != null && adTagLoader != null) { if (player != null && adTagLoader != null) {
adTagLoader.stop(); adTagLoader.stop();
} }
...@@ -508,14 +508,19 @@ public final class ImaAdsLoader ...@@ -508,14 +508,19 @@ public final class ImaAdsLoader
} }
@Override @Override
public void handlePrepareComplete(int adGroupIndex, int adIndexInAdGroup) { public void handlePrepareComplete(
AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup) {
if (adTagLoader != null) { if (adTagLoader != null) {
adTagLoader.handlePrepareComplete(adGroupIndex, adIndexInAdGroup); adTagLoader.handlePrepareComplete(adGroupIndex, adIndexInAdGroup);
} }
} }
@Override @Override
public void handlePrepareError(int adGroupIndex, int adIndexInAdGroup, IOException exception) { public void handlePrepareError(
AdsMediaSource adsMediaSource,
int adGroupIndex,
int adIndexInAdGroup,
IOException exception) {
if (adTagLoader != null) { if (adTagLoader != null) {
adTagLoader.handlePrepareError(adGroupIndex, adIndexInAdGroup, exception); adTagLoader.handlePrepareError(adGroupIndex, adIndexInAdGroup, exception);
} }
......
...@@ -265,7 +265,7 @@ public final class ImaAdsLoaderTest { ...@@ -265,7 +265,7 @@ public final class ImaAdsLoaderTest {
imaAdsLoader.onPositionDiscontinuity(Player.DISCONTINUITY_REASON_SEEK); imaAdsLoader.onPositionDiscontinuity(Player.DISCONTINUITY_REASON_SEEK);
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */ null)); adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_RESUME_REQUESTED, /* ad= */ null));
imaAdsLoader.handlePrepareError( imaAdsLoader.handlePrepareError(
/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, new IOException()); adsMediaSource, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, new IOException());
} }
@Test @Test
...@@ -836,7 +836,7 @@ public final class ImaAdsLoaderTest { ...@@ -836,7 +836,7 @@ public final class ImaAdsLoaderTest {
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
imaAdsLoader.requestAds(TEST_DATA_SPEC, adViewGroup); imaAdsLoader.requestAds(TEST_DATA_SPEC, adViewGroup);
imaAdsLoader.stop(); imaAdsLoader.stop(adsMediaSource);
InOrder inOrder = inOrder(mockAdDisplayContainer); InOrder inOrder = inOrder(mockAdDisplayContainer);
inOrder.verify(mockAdDisplayContainer).registerFriendlyObstruction(mockFriendlyObstruction); inOrder.verify(mockAdDisplayContainer).registerFriendlyObstruction(mockFriendlyObstruction);
......
...@@ -40,10 +40,10 @@ import java.util.List; ...@@ -40,10 +40,10 @@ import java.util.List;
* *
* <p>{@link #start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener)} will be called * <p>{@link #start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener)} will be called
* when an ads media source first initializes, at which point the loader can request ads. If the * when an ads media source first initializes, at which point the loader can request ads. If the
* player enters the background, {@link #stop()} will be called. Loaders should maintain any ad * player enters the background, {@link #stop(AdsMediaSource)} will be called. Loaders should
* playback state in preparation for a later call to {@link #start(AdsMediaSource, DataSpec, Object, * maintain any ad playback state in preparation for a later call to {@link #start(AdsMediaSource,
* AdViewProvider, EventListener)}. If an ad is playing when the player is detached, update the ad * DataSpec, Object, AdViewProvider, EventListener)}. If an ad is playing when the player is
* playback state with the current playback position using {@link * detached, update the ad playback state with the current playback position using {@link
* AdPlaybackState#withAdResumePositionUs(long)}. * AdPlaybackState#withAdResumePositionUs(long)}.
* *
* <p>If {@link EventListener#onAdPlaybackState(AdPlaybackState)} has been called, the * <p>If {@link EventListener#onAdPlaybackState(AdPlaybackState)} has been called, the
...@@ -218,26 +218,31 @@ public interface AdsLoader { ...@@ -218,26 +218,31 @@ public interface AdsLoader {
/** /**
* Stops using the ads loader for playback and deregisters the event listener. Called on the main * Stops using the ads loader for playback and deregisters the event listener. Called on the main
* thread by {@link AdsMediaSource}. * thread by {@link AdsMediaSource}.
*
* @param adsMediaSource The ads media source requesting to stop loading/playing ads.
*/ */
void stop(); void stop(AdsMediaSource adsMediaSource);
/** /**
* Notifies the ads loader that preparation of an ad media period is complete. Called on the main * Notifies the ads loader that preparation of an ad media period is complete. Called on the main
* thread by {@link AdsMediaSource}. * thread by {@link AdsMediaSource}.
* *
* @param adsMediaSource The ads media source for which preparation of ad media completed.
* @param adGroupIndex The index of the ad group. * @param adGroupIndex The index of the ad group.
* @param adIndexInAdGroup The index of the ad in the ad group. * @param adIndexInAdGroup The index of the ad in the ad group.
*/ */
void handlePrepareComplete(int adGroupIndex, int adIndexInAdGroup); void handlePrepareComplete(AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup);
/** /**
* Notifies the ads loader that the player was not able to prepare media for a given ad. * Notifies the ads loader that the player was not able to prepare media for a given ad.
* Implementations should update the ad playback state as the specified ad has failed to load. * Implementations should update the ad playback state as the specified ad has failed to load.
* Called on the main thread by {@link AdsMediaSource}. * Called on the main thread by {@link AdsMediaSource}.
* *
* @param adsMediaSource The ads media source for which preparation of ad media failed.
* @param adGroupIndex The index of the ad group. * @param adGroupIndex The index of the ad group.
* @param adIndexInAdGroup The index of the ad in the ad group. * @param adIndexInAdGroup The index of the ad in the ad group.
* @param exception The preparation error. * @param exception The preparation error.
*/ */
void handlePrepareError(int adGroupIndex, int adIndexInAdGroup, IOException exception); void handlePrepareError(
AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup, IOException exception);
} }
...@@ -259,7 +259,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> { ...@@ -259,7 +259,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
contentTimeline = null; contentTimeline = null;
adPlaybackState = null; adPlaybackState = null;
adMediaSourceHolders = new AdMediaSourceHolder[0][]; adMediaSourceHolders = new AdMediaSourceHolder[0][];
mainHandler.post(adsLoader::stop); mainHandler.post(() -> adsLoader.stop(/* adsMediaSource= */ this));
} }
@Override @Override
...@@ -385,7 +385,9 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> { ...@@ -385,7 +385,9 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
mainHandler.post( mainHandler.post(
() -> () ->
adsLoader.handlePrepareComplete( adsLoader.handlePrepareComplete(
mediaPeriodId.adGroupIndex, mediaPeriodId.adIndexInAdGroup)); /* adsMediaSource= */ AdsMediaSource.this,
mediaPeriodId.adGroupIndex,
mediaPeriodId.adIndexInAdGroup));
} }
@Override @Override
...@@ -402,7 +404,10 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> { ...@@ -402,7 +404,10 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
mainHandler.post( mainHandler.post(
() -> () ->
adsLoader.handlePrepareError( adsLoader.handlePrepareError(
mediaPeriodId.adGroupIndex, mediaPeriodId.adIndexInAdGroup, exception)); /* adsMediaSource= */ AdsMediaSource.this,
mediaPeriodId.adGroupIndex,
mediaPeriodId.adIndexInAdGroup,
exception));
} }
} }
......
...@@ -9029,13 +9029,18 @@ public final class ExoPlayerTest { ...@@ -9029,13 +9029,18 @@ public final class ExoPlayerTest {
AdsLoader.EventListener eventListener) {} AdsLoader.EventListener eventListener) {}
@Override @Override
public void stop() {} public void stop(AdsMediaSource adsMediaSource) {}
@Override @Override
public void handlePrepareComplete(int adGroupIndex, int adIndexInAdGroup) {} public void handlePrepareComplete(
AdsMediaSource adsMediaSource, int adGroupIndex, int adIndexInAdGroup) {}
@Override @Override
public void handlePrepareError(int adGroupIndex, int adIndexInAdGroup, IOException exception) {} public void handlePrepareError(
AdsMediaSource adsMediaSource,
int adGroupIndex,
int adIndexInAdGroup,
IOException exception) {}
} }
private static class FakeAdViewProvider implements AdsLoader.AdViewProvider { private static class FakeAdViewProvider implements AdsLoader.AdViewProvider {
......
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