Datazoom Gen 1 to Gen 2 migration guide
In this article, we will discuss the transition from our Android ExoPlayer Gen 1 adapter to the Android Media3 Gen 2 adapter. For a comprehensive overview of both technologies, please refer to the documents below.
Initialization
We have made significant updates to our Gen 2 adapter, particularly in terms of our API. We are working to standardize our SDK and unify it across multiple platforms.
Gen 1
var exoPlayerCollector = ExoPlayerCollector().create(player, context)
exoPlayerCollector?.setConfig(new DatazoomConfig(configId, configUrl))
exoPlayerCollector?.connect(new DZBeaconConnector.ConnectionListener() {
override fun onSuccess(DZEventCollector dzEventCollector) {
// Everything is setup, collector initialization complete
}
override fun onError(Throwable t) {
// Error while creating exo player collector
}
});
Gen 2
We have made changes to our public API and intialization is also changed completely.
API
import com.datazoom.sdk.Datazoom
import com.datazoom.sdk.Config
fun Datazoom.init(config: Config)
Example
import com.datazoom.sdk.Datazoom
import com.datazoom.sdk.logs.LogLevel
import com.datazoom.sdk.Config.Builder
Datazoom.init(
build(
configurationId = {YOUR_API_KEY},
block = {
logLevel(LogLevel.VERBOSE)
}
)
)
Creating context or adapter
Creating context or adapter is one of the most important part of our SDK. We have improved our ways of creating context here as well.
Gen 1
var exoPlayerCollector = ExoPlayerCollector().create(player, context)
Gen 2
API
import androidx.media3.exoplayer.ExoPlayer
import com.datazoom.sdk.BaseContext
import com.datazoom.sdk.Datazoom
import com.datazoom.sdk.DzAdapter
/* BaseContext is optional, meant for special usecase */
fun Datazoom.createContext(exoPlayer: ExoPlayer, base: BaseContext) : DzAdapter
Example
import com.datazoom.sdk.Datazoom
import com.datazoom.sdk.DzAdapter
/* BaseContext is optional, meant for special usecase */
val adapter: DzAdapter = Datazoom.createContext(exoPlayer)
Custom Events
Gen 1
var event = Event("Custom_Event_Name", new JSONArray())
dzEventCollector.addCustomEvent(event);
OR
var event = Event(type: String, metadata: ConcurrentHashMap<String, Object>)
dzEventCollector.addCustomEvent(event);
Gen 2
Player Context
API
import com.datazoom.sdk.DzAdapter
fun DzAdapter.generateEvent(name: String, payload: Map<String, Any>)
Example
import com.datazoom.sdk.DzAdapter
yourAdapter.generateEvent(
name = "test",
payload =
hashMapOf(
"property" to "abc",
"property2" to "xyz",
)
)
Global Context
API
import com.datazoom.sdk.Datazoom
fun Datazoom.generateEvent(name: String, payload: Map<String, Any>)
Example
import com.datazoom.sdk.Datazoom
Datazoom.generateEvent(
name = "test",
payload =
hashMapOf(
"property" to "abc",
"property2" to "xyz",
)
)
Custom Metadata
Gen 1
Global context
Set metadata
val appSessionMapTest = ConcurrentHashMap<String, Any>()
appSessionMapTest["key"] = "value"
DZEventCollector.setAppSessionCustomMetadata(appSessionMapTest)
Get metadata
DZEventCollector.getAppSessionCustomMetadata() : ConcurrentHashMap<String, Any>()
Update metadata
DZEventCollector.updateAppSessionCustomMetadata ("key", "value")
Delete metadata
DZEventCollector.clearAppSessionCustomMetadata();
Player metadata
Set metadata
val appPlayerMapTest = ConcurrentHashMap<String, Any>()
appPlayerMapTest["key"] = "value"
DZEventCollector.setPlayerSessionCustomMetadata(appPlayerMapTest)
Get metadata
DZEventCollector.getPlayerSessionCustomMetadata(): ConcurrentHashMap<String, Any>()
Update metadata
DZEventCollector.updatePlayerSessionCustomMetadata ("key", "value")
Delete metadata
DZEventCollector.clearPlayerSessionCustomMetadata();
Gen 2
Global context
Set metadata
API
import com.datazoom.sdk.Datazoom
fun Datazoom.setMetadata(metadata: Map<String, Any>)
Example
import com.datazoom.sdk.Datazoom
Datazoom.setMetadata(
hashMapOf(
"property" to "custom property",
"property2" to "custom property2",
)
)
Get metadata
API
import com.datazoom.sdk.Datazoom
fun Datazoom.getMetadata() : HashMap<String, Any>()
Example
import com.datazoom.sdk.Datazoom
val metdata: Map<String, Any> = Datazoom.getMetadata()
Clear metadata
API
import com.datazoom.sdk.Datazoom
fun Datazoom.clearMetadata()
Example
import com.datazoom.sdk.Datazoom
Datazoom.clearMetadata()
Player metadata
Set metadata
API
import com.datazoom.sdk.DzAdapter
fun DzAdapter.setMetadata(metadata: Map<String, Any>)
Example
import com.datazoom.sdk.DzAdapter
yourAdapter.setMetadata(
hashMapOf(
"property" to "custom property",
"property2" to "custom property2",
)
)
Get metadata
API
import com.datazoom.sdk.DzAdapter
fun DzAdapter.getMetadata(): Map<String, Any>
Example
import com.datazoom.sdk.DzAdapter
val metdata: Map<String, Any> = yourAdapter.getMetadata()
Delete metadata
API
import com.datazoom.sdk.DzAdapter
fun DzAdapter.clearMetadata()
Example
import com.datazoom.sdk.DzAdapter
yourAdapter.clearMetadata()
IMA Ad Events
Gen 1
adsLoader = ImaAdsLoader.Builder(this)
.setAdEventListener(new AdEvent.AdEventListener {
override fun onAdEvent(AdEvent : adEvent) {
exoPlayerCollector?.trackIMAAdEvent(adEvent)
}
})
.setAdErrorListener {new AdErrorEvent.AdErrorListener {
override fun onAdError(adError: AdErrorEvent?) {
exoPlayerCollector?.trackIMAAdErrorEvent(adError)}
})} .build()
Gen 2
API
We need Datazoom IMA extension to use this feature
import com.datazoom.sdk.DzAdapter
import com.google.ads.interactivemedia.v3.api.AdEvent
/* We need Datazoom IMA extension to use this feature */
fun DzAdapter.sendAdEvent(adEvent: AdEvent)
Example
import com.datazoom.sdk.DzAdapter
import com.google.ads.interactivemedia.v3.api.AdEvent
import androidx.media3.exoplayer.ima.ImaAdsLoader
adsLoader =
ImaAdsLoader.Builder(context)
.setAdEventListener { yourAdapter?.sendAdEvent(it) }
.setAdErrorListener {}
.build()
Comments
0 comments
Article is closed for comments.