Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Initialization

  1. 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

Inside Application class:

Code Block
languagekotlin
initializeAdPlayer(this)

or anywhere else (not recommended):

Code Block
languagekotlin
AdPlayer.initialize(context)

Java

Code Block
languagejava
AdPlayer.initialize(context);
Warning

Calling any of the AdPlayer APIs before initialization will result in errors!

Info

Before this method is called, the SDK will not perform any operations and will not use any resources (memory, cpu, network etc.).

  • Initialization allows to provide an additional optional parameter for user identification. Providing this parameter will allow us to identify a specific user within our system for debugging or sharing of information.

Note

The identifier must be anonymized. Do not put here any information that isn’t unique to your system like email address.

Kotlin

Inside Application class:

Code Block
languagekotlin
initializeAdPlayer(this, userIdentifier)

or anywhere else (not recommended):

Code Block
languagekotlin
AdPlayer.initialize(context, userIdentifier)

Java

Code Block
languagejava
AdPlayer.initialize(context, userIdentifier);

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

Inside Application class:

Code Block
languagekotlin
initializeAdPlayerPublisher(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, tagId: String? ->
    // tag initialization failed
}

or anywhere else (not recommended):

Code Block
languagekotlin
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, tagId: String? ->
    // 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
languagejava
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
languagexml
<!--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 layout_height and any attempt to manually change the height will be ignored and assigned according to the content and configuration of the player tag.

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
languagekotlin
val placement = AdPlayerPlacementView(context).apply { 
    attachPlayerTag(tagId)
}

Java

Code Block
languagejava
AdPlayerPlacementView placement = new AdPlayerPlacementView(context);
placement.attachPlayerTag(tagId);