Initialization
Initialize the SDK. Call SDK initialization in Application.onCreate():
Info |
---|
Your application may not contain a custom implementation of the Application class. In such a case you should create one. |
Kotlin
Code Block | ||
---|---|---|
| ||
AdPlayer.initialize(context) |
Java
Code Block | ||
---|---|---|
| ||
AdPlayer.initialize(context); |
Warning |
---|
Calling any of the |
Before this method is called, the SDK will not perform any operations and will not use any resources (memory, cpu, network etc.).
2. Initialize the player tags. To be called right after initialize in Application.onCreate().
In case the tags belong to more than one publisher, this method must be called once per publisher.
Kotlin
Code Block | ||
---|---|---|
| ||
AdPlayer.initializePublisher(publisherId) { // at least one call to addTag is required addTag(tag1Id) { // configure your tag here } addTag(tag2Id) { // configure your tag here } } // this is optional .onTagReady { tag: AdPlayerTag -> // tag is ready to be displayed } // this is optional .onError { error: AdPlayerError -> // tag initialization failed } |
The addTag
method must be called at least once (a publisher cannot be initialized without tags) and must be called again for every player tag of this publisher that is expected to be presented in the application.
Java
Code Block | ||
---|---|---|
| ||
AdPlayerTagConfiguration tag1 = new AdPlayerTagConfiguration(tag1Id);
// configure your tag here
AdPlayerTagConfiguration tag2 = new AdPlayerTagConfiguration(tag2Id);
// configure your tag here
AdPlayerPublisherConfiguration publisher = new AdPlayerPublisherConfiguration(publisherId, tag1, tag2);
// the callback is optional
AdPlayer.initializePublisher(publisher, new AdPlayerTagInitCallback() {
@Override
public void onTagReady(@NonNull AdPlayerTag adPlayerTag) {
// tag is ready to be displayed
}
@Override
public void onError(@NonNull AdPlayerError adPlayerError, @Nullable String tagId) {
// tag initialization failed
}
}); |
At least one AdPlayerTagConfiguration
must be provided in the constructor of AdPlayerPublisherConfiguration
(a publisher configuration cannot be instantiated without tags).
All the player tags of this publisher that are expected to be presented in the application must be provided in the constructor of AdPlayerPublisherConfiguration
.
Warning |
---|
A player tag that won’t be initialized successfully won’t be presented and won’t function! |
Note |
---|
A player tag should be initialized only once. |
You can find the available configuration options in the AdPlayerTag APIs section.
Preparing the UI placement(s) of your player tag(s)
Warning |
---|
A player tag may be displayed only in one placement view. Displaying the same tag in multiple placement views is not supported and may lead to unexpected behavior. |
Info |
---|
Use your dashboard to configure the content, visualization and behavior of the player. |
Presenting using static XML layout
Add a AdPlayerPlacementView
XML element to your layout in the position where you want the player to be displayed. Assign the ID of the player tag that should be presented in this placement by adding the following configuration to the element: app:player_tag=<your tag ID>
.
Code Block | ||
---|---|---|
| ||
<!--layout_height will be ignored--> <com.adservrs.adplayer.placements.AdPlayerPlacementView android:id="@+id/ad_1" android:layout_width="match_parent" android:layout_height="wrap_content" app:player_tag=<your tag ID> /> |
Note |
---|
As the player must keep its aspect ratio to be presented properly, the value of |
Once the player tag is initialized and the AdPlayerPlacementView
is visible on the screen, the player will be loaded and the content of the assigned player tag will be presented.
Note that initialization time may vary depending on many conditions. Therefore, the user may not see a player on the screen right away.
Present using dynamically created layout
If you wish to programmatically create the AdPlayerPlacementView
or simply reuse the same XML layout to present different players, then AdPlayerPlacementView.attachPlayerTag(tagId)
must be called to associate a player tag to the placement.
Kotlin
Code Block | ||
---|---|---|
| ||
val placement = AdPlayerPlacementView(context).apply { attachPlayerTag(tagId) } |
Java
Code Block | ||
---|---|---|
| ||
AdPlayerPlacementView placement = new AdPlayerPlacementView(context); placement.attachPlayerTag(tagId); |