-jio-start-block-type-2
-jio-style-title
Instream audio ads seamlessly integrate within your app's audio content, offering various formats like pre-roll, mid-roll, and post-roll.
Complete GETTING STARTED section and INITIALIZE SDK section before starting this section.
-jio-style-title
Cache instream audio ads by initializing a JioAdView
, setting up an ad listener, creating an ad container, adding the ad view, and initiating the caching process with a single call to jioAdViewInstreamAudio.cacheAd()
var jioAdViewInstreamAudio : JioAdView
// context passed here MUST be Activity context.
jioAdViewInstreamAudio = JioAdView (this, ”<ADSPOT_KEY_GOES_HERE>“, JioAdView.AD_TYPE.INSTREAM_AUDIO)
jioAdViewInstreamAudio !!.setAdListener(object: JioAdListener() {
override fun onAdFailedToLoad(jioAdView: JioAdView?, jioAdError: JioAdError?) {
// Error Callback
}
override fun onAdPrepared(jioAdView: JioAdView?) {
// Success callback
}
override fun onAdClosed( jioAdView: JioAdView?,isVideoCompleted: Boolean,isEligibleForReward: Boolean) {
// When Ad is closed
}
override fun onAdRender(jioAdView: JioAdView?){
// When ad is rendered on screen
}
override fun onAdMediaEnd(jioAdView: JioAdView?) {
// When media ended
}
})
val audioCompanionAdContainer = findViewById<FrameLayout>(R.id.companionAdContainer)
jioAdViewInstreamAudio?.cacheAd()
-jio-style-title
Load the instream audio ad when it's in the prepared state, utilizing jioAdViewInstreamAudio.loadAd()
for rendering.
if(jioAdViewInstreamAudio.getAdState() == JioAdView.AdState.PREPARED) {
jioAdViewInstreamAudio?.addView(jioAdViewInstreamAudio?.getAdView())
jioAdViewInstreamAudio?.loadAd();
}
-jio-end-block-type-2
-jio-start-block-type-2
-jio-style-title
Destroy the instream audio ad object by calling jioAdViewInstreamAudio.onDestroy()
in the onDestroy()
method of your activity to ensure proper cleanup during the activity lifecycle.
override fun onDestroy() {
if (jioAdViewInstreamAudio!= null) {
jioAdViewInstreamAudio.onDestroy()
}
super.onDestroy()
}
-jio-style-title
Use the below APIs to pause or resume Instream Audio Ad
//to pause Instream Audio Ad
jioAdViewInstreamAudio.pauseAd()
//to show all the audio controls
jioAdViewInstreamAudio.resumeAd()
-jio-end-block-type-2