Skip to content

Instantly share code, notes, and snippets.

@anirudhramanan
Last active March 31, 2020 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudhramanan/70c499c5767a2d325eec283fcdae69ed to your computer and use it in GitHub Desktop.
Save anirudhramanan/70c499c5767a2d325eec283fcdae69ed to your computer and use it in GitHub Desktop.
Madman integration steps

Madman Integration

If you need to integrate directly with the madman library, follow the below steps

1. Get Madman

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' 
}

2. Initialise Madman

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.

3. Create AdRenderer

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

4. Request Ads

  • 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)

Madman Exo-Player Integration

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment