In this documentation we explained how to use Huawei-Exoplayer adapter in android.
Click here to check the medium post about this adapter.
- Sign in to Huawei Developer Console and create an ad unit for Roll Ads.
Exoplayer is an extensible media player for Android developed by Google. Click here to check the offical Github page of the exoplayer.
Roll ads are displayed as short videos or images, before, during, or after the video content is played. Click here to learn more about roll ads.
In the project-level build.gradle, include Huawei's Maven repository.
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } // Add this line
maven {url "https://jitpack.io"} // Add this line
}
...
allprojects {
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } //Add this line
maven {url "https://jitpack.io"} // Add this line
}
}
In the app-level build.gradle, include following dependencies and enable multidex for the project :
dependencies {
...
implementation 'com.github.Explore-In-HMS:huawei.ads.exoplayer_adapter:v1.0.0'
implementation 'com.google.android.exoplayer:exoplayer:<any version>'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.huawei.hms:ads:3.4.49.301'
}
defaultConfig {
multiDexEnabled true // enable multidex for the project
}
Adapter implementation code as follows.
new HwExoPlayerAdapter.Builder(Context context, PlayerView playerview, "Huawei Roll ad unit id")
.setAdItem(Placement.PREROLL, true)
.setAdItem(Placement.FIRST_QUARTILE, false)
.setAdItem(Placement.MIDDLE, true)
.setAdItem(Placement.THIRD_QUARTILE, false)
.setAdItem(Placement.POSTROLL, true)
//optional, used for customize the ad requests
.setAppLanguage("en")
.setChildProtectionCOPPA(true)
.setTcfConsent("")
.setGender(Gender.MALE)
.setOnlyNonPersonalized(true)
.setUnderOfAgeConsent(true)
.setLocation(Location location)
.useLocationForRequest(true)
.build();
NOTE: adapter must be build before SimpleExoPlayer.prepare() method called.
When creating the builder 3 parameters must be given ; context, PlayerView instance, and Roll ad unit id.
This method is used to specify the video ads according to the placement and skippable value.
For the placement, There are 5 placements you can choose (Preroll, FirstQuartile, Middle, ThidQuartile, and Post-roll). According to these placements, the ad will pop up in the video content. For example, 2 Ad items are created and their placements are middle and post-roll. In the middle and at the end of your video content, ads will be shown.
NOTE: Only one ad will be shown for each placement. Ad pods are not currently supported .
Used to decide if the ad is skippable or not. Give true value for skippable ads.
Sets the language in which an ad needs to be returned for an app.
Sets whether to process ad requests according to the COPPA. Use value true to allow it.
Sets the user consent string that complies with TCF v2.0.
Sets the gender. use Huawei Gender Constant class to set it. (e.g. Gender.MALE)
Sets whether to request non-personalized ads. Use value true to allow only non-personalized ads.
Sets whether to process ad requests as directed to users under the age of consent. Use value true to allow it.
Sets the location information passed by your app.
Sets whether to carry the location information in an ad request. By default, the information is carried.