Search in sources :

Example 1 with VideoAdUnit

use of org.prebid.mobile.VideoAdUnit in project prebid-mobile-android by prebid.

the class RubiconBannerVideoGamDemoActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
    PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_VAST_RUBICON);
    VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
    parameters.setMimes(Arrays.asList("video/mp4"));
    parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
    // parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
    parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
    // parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
    parameters.setPlacement(Signals.Placement.InBanner);
    // parameters.setPlacement(new Signals.Placement(2));
    VideoAdUnit adUnit = new VideoAdUnit("1001-1", 300, 250);
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    final AdManagerAdView amBanner = new AdManagerAdView(this);
    amBanner.setAdUnitId(Constants.DFP_VAST_ADUNIT_ID_RUBICON);
    amBanner.setAdSizes(new AdSize(300, 250));
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adFrame.addView(amBanner);
    amBanner.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {

                @Override
                public void success(int width, int height) {
                    amBanner.setAdSizes(new AdSize(width, height));
                }

                @Override
                public void failure(@NonNull PbFindSizeError error) {
                    Log.d("MyTag", "error: " + error);
                }
            });
        }
    });
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    // region PrebidMobile Mobile API 1.0 usage
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    adUnit.setAutoRefreshPeriodMillis(millis);
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            AdManagerAdRequest request = builder.build();
            amBanner.loadAd(request);
        }
    });
}
Also used : PbFindSizeError(org.prebid.mobile.addendum.PbFindSizeError) VideoAdUnit(org.prebid.mobile.VideoAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) AdSize(com.google.android.gms.ads.AdSize) FrameLayout(android.widget.FrameLayout) NonNull(androidx.annotation.NonNull) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Aggregations

FrameLayout (android.widget.FrameLayout)1 NonNull (androidx.annotation.NonNull)1 AdListener (com.google.android.gms.ads.AdListener)1 AdSize (com.google.android.gms.ads.AdSize)1 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)1 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)1 OnCompleteListener (org.prebid.mobile.OnCompleteListener)1 ResultCode (org.prebid.mobile.ResultCode)1 VideoAdUnit (org.prebid.mobile.VideoAdUnit)1 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)1 PbFindSizeError (org.prebid.mobile.addendum.PbFindSizeError)1