Default UI is not rendering & No Events are firing after LOADED event | IMA SDK Android

115 views
Skip to first unread message

Anuja Kothekar

unread,
Dec 22, 2021, 5:28:33 AM12/22/21
to Interactive Media Ads SDK
Hi,
I have referred Advanced Example given on site & I am using preloading for ad. I am creating adDisplayContainer with empty frame layout before requesting ads. Code snippet as below: 

fun requestAds() {

   videoAdPlayer = object : VideoAdPlayer {
                    override fun getAdProgress(): VideoProgressUpdate {
                        return if (myVideoPlayer == null || (myVideoPlayer?.getDuration() ?: 0 <= 0)) {
                            VideoProgressUpdate.VIDEO_TIME_NOT_READY
                        } else if (myVideoPlayer != null) {
                            VideoProgressUpdate(myVideoPlayer!!.getCurrentPosition().toLong(),
                                myVideoPlayer!!.getDuration().toLong())
                        } else {
                            VideoProgressUpdate.VIDEO_TIME_NOT_READY
                        }
                    }

                    override fun getVolume(): Int {
                        return myVideoPlayer?.getVolume() ?: 0
                    }

                    override fun addCallback(p0: VideoAdPlayer.VideoAdPlayerCallback?) {
                        if (p0 != null) {
                            videoPlayerCallbacks.add(p0)
                        }
                    }

                    override fun loadAd(adMediaInfo: AdMediaInfo?, adpodInfo: AdPodInfo?) {
                        if (adMediaInfo != null && !TextUtils.isEmpty(adMediaInfo.url)) {
                            mCurrentMediaInfo = adMediaInfo
                            var duration: Int? = null
                            duration = (mAdsManager?.currentAd?.duration ?: 0).toInt()
                            adViewLayout.getAdViewController()
                                ?.addMediationUrl(adMediaInfo.url, this@VideoController,
                                    duration, -1, mAdsManager?.currentAd?.vastMediaHeight,
                                    mAdsManager?.currentAd?.vastMediaWidth)
                        }
                    }

                    override fun pauseAd(p0: AdMediaInfo?) {
                        e("**** pauseAd() $mIsCalledByDev")
                        myVideoPlayer?.pauseAd(mIsCalledByDev)
                        for (callback in videoPlayerCallbacks) {
                            callback.onPause(p0)
                        }
                    }

                    override fun playAd(p0: AdMediaInfo?) {
                        e("**** playAd()")
                        val playbackState = myVideoPlayer?.getPlayerState()
                        if (playbackState == MediaPlayer.STATE_PAUSED) {
                            myVideoPlayer?.resumeAd(mIsCalledByDev)
                            for (callback in videoPlayerCallbacks) {
                                callback.onResume(p0)
                            }
                        } else if (playbackState == MediaPlayer.STATE_PREPARED) {
                            myVideoPlayer?.startVideo()
                            for (callback in videoPlayerCallbacks) {
                                callback.onPlay(p0)
                            }
                        }

                    }

                    override fun release() {
                        e("**** release()")
                        myVideoPlayer?.release()
                    }

                    override fun removeCallback(p0: VideoAdPlayer.VideoAdPlayerCallback?) {
                        e("**** removeCallback()")
                        if (p0 != null) {
                            videoPlayerCallbacks.remove(p0)
                        }
                    }

                    override fun stopAd(p0: AdMediaInfo?) {
                        e("**** stopAd()")
                        myVideoPlayer?.stopAds()
                    }
                }
                mAdUiContainer = FrameLayout(mContext)
                val mAdDisplayContainer =
                    ImaSdkFactory.createAdDisplayContainer(mAdUiContainer, videoAdPlayer)
                mAdDisplayContainer.player = videoAdPlayer
                mSdkFactory = ImaSdkFactory.getInstance()
                val request = mSdkFactory!!.createAdsRequest()
                request!!.adTagUrl = mAdTagUrl
                val imaSdkSettings = mSdkFactory!!.createImaSdkSettings()!!
                mAdsLoader =
                    mSdkFactory?.createAdsLoader(mContext, imaSdkSettings, mAdDisplayContainer!!)
                mAdsLoader?.addAdErrorListener(this)
                mAdsLoader?.addAdsLoadedListener(this)

                // Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.
                mAdsLoader?.requestAds(request)

}


and in onAdsManagerLoaded I have

override fun onAdsManagerLoaded(adsManagerLoadedEvent: AdsManagerLoadedEvent?) {
e("**** adsManagerLoaded()")
d("{${mJioAdView.getAdSpotId()}}: onAdsManagerLoaded")
if (adsManagerLoadedEvent?.adsManager != null) {
mAdsManager = adsManagerLoadedEvent.adsManager
if (mAdsManager != null && mSdkFactory != null) {
mAdsManager!!.addAdErrorListener(this)
mAdsManager!!.addAdEventListener(this)
val adsRenderingSettings: AdsRenderingSettings =
mSdkFactory!!.createAdsRenderingSettings()
adsRenderingSettings.enablePreloading = true
mAdsManager?.init(adsRenderingSettings)
}
}


Other than these changes, I am using my own video player with android default mediaplayer and connected that player with callbacks as suggested in advanced sample.

I am getting adevent LOADED and after that AD_PROGRESS, but apart from these 2 events I am not able to receive any other event in onAdEvent of eventlistener. Also, the webview containing skip button & ad click is not getting rendered on UI container. I have tried lot many things but was not able to crack it.
Please help.

Regards,
Anuja


IMA SDK

unread,
Dec 23, 2021, 2:25:46 AM12/23/21
to anuja.k...@gmail.com, ima...@googlegroups.com

Hello Anuja,

 

I'm Michael from IMA SDK Team, thank you for reaching out to us.

 

The Advance sample app we have should work well with the AdEvent Listener as expected. Our recommendation would be to make a copy of that project then add specific features that would fit your use case one by one to see where the issue is coming from and to avoid it or any implementation issues.

 

Additionally, we do have a guide for Preloading Media, it would be best to check this out first for better understanding how it should be implemented.

 

Should you still encounter any issues upon following the recommendations above, it would be best to share your sample project implementation for further investigation.

Regards,

Google Logo
Michael Angelo Legaspi
IMA SDK Team
 


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