Search in sources :

Example 1 with AdOverlayInfo

use of androidx.media3.common.AdOverlayInfo in project media by androidx.

the class AdTagLoader method addListenerWithAdView.

/**
 * Starts passing events from this instance (including any pending ad playback state) and
 * registers obstructions.
 */
public void addListenerWithAdView(EventListener eventListener, AdViewProvider adViewProvider) {
    boolean isStarted = !eventListeners.isEmpty();
    eventListeners.add(eventListener);
    if (isStarted) {
        if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
            // Pass the existing ad playback state to the new listener.
            eventListener.onAdPlaybackState(adPlaybackState);
        }
        return;
    }
    lastVolumePercent = 0;
    lastAdProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
    lastContentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
    maybeNotifyPendingAdLoadError();
    if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
        // Pass the ad playback state to the player, and resume ads if necessary.
        eventListener.onAdPlaybackState(adPlaybackState);
    } else if (adsManager != null) {
        adPlaybackState = new AdPlaybackState(adsId, getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
        updateAdPlaybackState();
    }
    for (AdOverlayInfo overlayInfo : adViewProvider.getAdOverlayInfos()) {
        adDisplayContainer.registerFriendlyObstruction(imaFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail));
    }
}
Also used : AdOverlayInfo(androidx.media3.common.AdOverlayInfo) AdPlaybackState(androidx.media3.common.AdPlaybackState)

Example 2 with AdOverlayInfo

use of androidx.media3.common.AdOverlayInfo in project media by androidx.

the class ImaServerSideAdInsertionMediaSource method registerFriendlyObstructions.

private static void registerFriendlyObstructions(ImaSdkFactory imaSdkFactory, StreamDisplayContainer container, AdViewProvider adViewProvider) {
    for (int i = 0; i < adViewProvider.getAdOverlayInfos().size(); i++) {
        AdOverlayInfo overlayInfo = adViewProvider.getAdOverlayInfos().get(i);
        container.registerFriendlyObstruction(imaSdkFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
    }
}
Also used : AdOverlayInfo(androidx.media3.common.AdOverlayInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Example 3 with AdOverlayInfo

use of androidx.media3.common.AdOverlayInfo in project media by androidx.

the class ImaAdsLoaderTest method setUp.

@Before
public void setUp() {
    setupMocks();
    fakePlayer = new FakeExoPlayer();
    adViewGroup = new FrameLayout(getApplicationContext());
    View adOverlayView = new View(getApplicationContext());
    adViewProvider = new AdViewProvider() {

        @Override
        public ViewGroup getAdViewGroup() {
            return adViewGroup;
        }

        @Override
        public ImmutableList<AdOverlayInfo> getAdOverlayInfos() {
            return ImmutableList.of(new AdOverlayInfo(adOverlayView, AdOverlayInfo.PURPOSE_CLOSE_AD));
        }
    };
    audioAdsAdViewProvider = () -> null;
    imaAdsLoader = new ImaAdsLoader.Builder(getApplicationContext()).setImaFactory(mockImaFactory).setImaSdkSettings(mockImaSdkSettings).setVideoAdPlayerCallback(mockVideoAdPlayerCallback).build();
    imaAdsLoader.setPlayer(fakePlayer);
    adsMediaSource = new AdsMediaSource(new FakeMediaSource(CONTENT_TIMELINE), TEST_DATA_SPEC, TEST_ADS_ID, new DefaultMediaSourceFactory((Context) getApplicationContext()), imaAdsLoader, adViewProvider);
    timelineWindowDefinitions = new TimelineWindowDefinition[] { getInitialTimelineWindowDefinition(TEST_ADS_ID) };
    adsLoaderListener = new TestAdsLoaderListener(/* periodIndex= */
    0);
    when(mockAdsManager.getAdCuePoints()).thenReturn(PREROLL_CUE_POINTS_SECONDS);
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ViewGroup(android.view.ViewGroup) ImmutableList(com.google.common.collect.ImmutableList) View(android.view.View) AdOverlayInfo(androidx.media3.common.AdOverlayInfo) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) FrameLayout(android.widget.FrameLayout) AdViewProvider(androidx.media3.common.AdViewProvider) AdsMediaSource(androidx.media3.exoplayer.source.ads.AdsMediaSource) Before(org.junit.Before)

Aggregations

AdOverlayInfo (androidx.media3.common.AdOverlayInfo)3 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 AdViewProvider (androidx.media3.common.AdViewProvider)1 DefaultMediaSourceFactory (androidx.media3.exoplayer.source.DefaultMediaSourceFactory)1 AdsMediaSource (androidx.media3.exoplayer.source.ads.AdsMediaSource)1 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)1 CuePoint (com.google.ads.interactivemedia.v3.api.CuePoint)1 ImmutableList (com.google.common.collect.ImmutableList)1 Before (org.junit.Before)1