If you need to integrate directly with the madman library, follow the below steps
Add the jitpack dependency in your root build.gradle
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Add the madman dependency
dependencies {
// core madman library
implementation 'com.github.flipkart-incubator.madman:madman:$latest_version'
// optional network layer module for fetching vmap/vast from server, sending tracking events etc
implementation 'com.github.flipkart-incubator.madman:madman-okhttp:$latest_version'
}
val madman = Madman.Builder()
.setAdErrorListener(this) // ad error callbacks
.setAdLoadListener(this) // ad load callbacks
.setNetworkLayer(DefaultNetworkLayer(context)) // use the default network layer, override if necessary
.setAdEventListener(this) // ad event callbacks
.build(context)
Read the doc to understand the components in detail.
AdRenderer houses the logic for rendering the UI components on the top of the ad. The library provides a default layout for the ad overlay, which can be overriden if required.
val adRenderer = DefaultAdRenderer.Builder()
.setPlayer(this) // player interface
.setContainer(adViewGroup) // parent view to which the overlay gets added
.build(null) // passing null will fallback to default UI layout
To override the default layout, create a new AdViewBinder
and pass it while calling build
on the AdRenderer
val adViewBinder = AdViewBinder.Builder()
.setLayoutId(R.layout.ad_overlay) // layout of custom ad overlay
.setSkipViewId(R.id.skip_button) // specify the skip view id
.setClickThroughViewId(R.id.click_throught_button) // specify the learn more view id
.build()
val adRenderer = DefaultAdRenderer.Builder()
.setPlayer(this) // player interface
.setContainer(adViewGroup) // parent view to which the overlay gets added
.build(adViewBinder) // passing custom ad view binder
- From network:
val request = NetworkAdRequest()
request.setUrl(adTagUri.toString())
madman.requestAds(request, adRenderer)
- From local cache:
val request = StringAdRequest()
request.setResponse(adResponse)
madman.requestAds(request, adRenderer)
If you are using exo-player, you can directly use the MadmanAdLoader plugin which acts as a glue between the madman library and exo-player instance.
dependencies {
implementation 'com.github.flipkart-incubator.madman:madman-exoplayer-extension:$latest_version'
}
Checkout the demo app to understand the integration process in detail.