How to get companion ads' height and width using exoplayer Ima extension?

239 views
Skip to first unread message

ltsadevs

unread,
Sep 7, 2021, 9:44:26 AM9/7/21
to Interactive Media Ads SDK
I am using Exoplayer Ima extension and our ad server returns different ads with different companion ad size, so I wanted to get the size from loaded ad and then set the size of companion ad slot. 
adEvent.getAd() returns the ads but when I null check adEvent.getAd().getCompanionAds() it throws.
Can anyone let me know if there is any way to get companion ad size from the loaded ad response?

private class AdEventListener implements AdEvent.AdEventListener { 
  @Override 
  public void onAdEvent(AdEvent adEvent) {
      switch (adEvent.getType()) { 
             case STARTED: 
                   companionViewGroup.setVisibility(View.VISIBLE); 
                  break; 
              case ALL_ADS_COMPLETED: 
                   companionViewGroup.setVisibility(View.GONE);
                   break; 
              case LOADED: 
                  if (adEvent.getAd() != null && adEvent.getAd().getCompanionAds() != null) {
                        Log.d("TAG00", "height "+ 
                                        adEvent.getAd().getCompanionAds().get(0).getHeight()); 
                    }
                   break; 
         } 
     }
  }




E/AndroidRuntime: FATAL EXCEPTION: main
Process: <package_name>, PID: 3117
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
at com.google.ads.interactivemedia.v3.impl.data.c.getCompanionAds(SourceFile:2)
at <package_name>.activities.PlayerActivity$d.onAdEvent(SourceFile:1077)
at com.google.ads.interactivemedia.v3.internal.dg.b(SourceFile:10)
at com.google.ads.interactivemedia.v3.internal.cv.b(SourceFile:15)
at com.google.ads.interactivemedia.v3.internal.ed.k(SourceFile:47)
at com.google.ads.interactivemedia.v3.internal.ej.f(SourceFile:5)
at com.google.ads.interactivemedia.v3.internal.eg.shouldOverrideUrlLoading(SourceFile:2)
at android.webkit.WebViewClient.shouldOverrideUrlLoading(WebViewClient.java:77)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(chromium-Monochrome.aab-stable-451515923:14)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

IMA SDK

unread,
Sep 7, 2021, 10:45:04 AM9/7/21
to d...@dthlivetv.com, ima...@googlegroups.com
Hi Itsadevs,

Thank you for reaching out to us with your question. I see that you have another post it appears that also has this exact same question on it. I will be responding back toyou in that one.

Regards,
Google Logo
William Pescherine
IMA SDK Team
 


ref:_00D1U1174p._5004Q2NS1U0:ref

ltsadevs

unread,
Sep 7, 2021, 11:13:08 AM9/7/21
to Interactive Media Ads SDK
Please reply to this one only. I have already deleted the previous one.

IMA SDK

unread,
Sep 7, 2021, 3:30:50 PM9/7/21
to d...@dthlivetv.com, ima...@googlegroups.com
Hi Itsadev,

Thank you for responding to us. I Have been looking more into this for you and would say that the best way to get the companion size is to look at the dynamic ad slots here . As in general when the companion ad is loaded it does it based on the size of the ad slot it is filling, and then adjusting it as it needs to fit the slot. So it would be possible that the companion ad is not the exact same size but close to the slot size and then fitted into it.

ltsadevs

unread,
Sep 8, 2021, 2:26:06 AM9/8/21
to Interactive Media Ads SDK
Hi,
Thanks for the response.

adEvent.getAd().getCompanionAds() throws null pointer exception though adEvent.getAd() returns ad.

    java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
        at com.google.ads.interactivemedia.v3.impl.data.c.getCompanionAds(SourceFile:2)

IMA SDK

unread,
Sep 8, 2021, 5:35:11 AM9/8/21
to d...@dthlivetv.com, ima...@googlegroups.com

Hi Itsadevs,

 

I work along with William, allow me to assist you here.

 

The getCompanionAds() method will only return the companions for the current ad when using DAI. It normally returns an empty list for Android client side SDK, and I believe you are using the android client-side SDK, is that correct? If so, then this is a normal behavior.

 

On the other hand, with regards to your use case "so I wanted to get the size from loaded ad and then set the size of companion ad slot", I just want to be clear that we require registering a companion ad slot prior to making the ad request, so it knows what size of companion to return. Based on that, it does not make sense to return a VAST without already having the companion ad container and registering it. Please refer to our documentation for guidelines on implementing companion ads.

Regards,

Google Logo
Michael Angelo Legaspi
IMA SDK Team
 


ref:_00D1U1174p._5004Q2NS1U0:ref
Reply all
Reply to author
Forward
0 new messages