Datazoom is a high-availability real-time data collection solution. This document summarizes how to integrate the Android MediaPlayer framework with the Datazoom platform.
- Login to Datazoom here: https://app.datazoom.io
- Add a Collector as indicated here: How to add a Collector
- Copy the
config key
that was created at the end of the process
Click the icon indicated below to copy the Configuration Key
You will see this message:
4. Replace the <configuration id from Datazoom>
with the Key you copied above.
5. Replace the <url given by Datazoom>
with <
https://platform.datazoom.io/beacon/v1/
>
6. Replace the <Videoview object>
with your videoView
identifier
Adding dependencies to your project
Add the following maven repository URL in your project's build.gradle file
// Snapshot Repository maven { url 'https://gitlab.com/api/v4/projects/18323233/packages/maven' } // Release Repository maven { url 'https://gitlab.com/api/v4/projects/10353305/packages/maven' }
Add the following dependency for Datazoom Android Media Player SDK in your project's build.gradle file's dependencies block
dependencies { implementation 'com.datazoom.android:base-collector-gold-adapter:2.0.3' implementation 'com.datazoom.android:base-collector-gold:2.0.6' }
Add
exoplayer:extension-ima
for ads tracking (optional).
implementation 'com.google.android.exoplayer:exoplayer-core:2.11.1' implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.1' implementation 'com.google.android.exoplayer:extension-ima:2.11.1'
Add retrofit library to your project if you don't have it already
implementation 'com.google.code.gson:gson:2.3.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1' implementation 'com.squareup.okhttp3:okhttp:3.4.1' implementation 'com.squareup.retrofit2:retrofit:2.3.0'
Add
DZAndroidVideoView
in your xml layout file<com.dz.adapter.android.DZAndroidVideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="300dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="10dp" />
Calling NativeAndroidCollector with configurations
String configId = <configuration id from Datazoom> String configUrl = <url given by Datazoom> VideoView videoView = <Videoview object> NativeAndroidCollector .create(this, activityMainBinding.videoView) .setConfig(new DatazoomConfig(configId, configUrl)) .connect(new DZBeaconConnector.ConnectionListener() { @Override public void onSuccess(DZEventCollector dzEventCollector) { } @Override public void onError(Throwable t) { } } );
After a successful connection using the following method to start or stop recording events
NativeAndroidCollector.startRecordingEvents(true); NativeAndroidCollector.startRecordingEvents(false);
IMA Observers (if you have ads)
NativeAndroidCollector.addIMAObservers(adsLoader);
Release player to reset data and timers
@Override protected void onDestroy() { super.onDestroy(); DZNativeAndroidAdapter.releasePlayer(); }
Custom Events & Metadata
Datazoom allows customers to collect custom events and custom metadata that don't originate from a video player.
Custom Metadata
a. Create a JSONArray with necessary metadata.
1. DZEventCollector.setCustomMetadata(new JSONArray("[" + "{\"custom_player_name\": \"Android Gold Media Player\"},"+ "{\"custom_domain\": \"demo.datazoom.io\"}"+ "]"));
or
HashMap<String, Object> metadata = new HashMap<String, Object>;
b. Add the metadata to DZEventCollector.
1. dzEventCollector.setDatazoomMetadata(metadata); or dzEventCollector.setCustomMetadata(HashMap<String, Object> metadata);
Example
@Override public void onSuccess(DZEventCollector dzEventCollector) { try { dzEventCollector.setDatazoomMetadata(new JSONArray("[{\"customPlayerName\": \"Exo Player\"}," + "{\"customDomain\": " + "\"platform.io\"}]")); } catch (JSONException e) { e.printStackTrace(); } }
ADD APP SESSION METADATA
(Metadata during the application session)
HashMap<String, Object> appSessionMapTest = new HashMap<>(); appSessionMapTest.put("key", "value"); DZEventCollector.setAppSessionCustomMetadata(appSessionMapTest);
READ APP SESSION METADATA
1. DZEventCollector.getAppSessionCustomMetadata()
UPDATE APP SESSION METADATA
1. DZEventCollector.updateAppSessionCustomMetadata("key", "value");
DELETE APP SESSION METADATA
1. DZEventCollector.clearAppSessionCustomMetadata()
ADD PLAYER SESSION METADATA
(Metadata during the player session)
HashMap<String, Object> appPlayerMapTest = new HashMap<>(); appPlayerMapTest.put("key", "value"); DZEventCollector.setPlayerSessionCustomMetadata(appPlayerMapTest);
READ PLAYER SESSION METADATA
1. DZEventCollector.getPlayerSessionCustomMetadata()
UPDATE PLAYER SESSION METADATA
1. DZEventCollector.updatePlayerSessionCustomMetadata("key", "value");
DELETE PLAYER SESSION METADATA
1. DZEventCollector.clearPlayerSessionCustomMetadata();
ADD CUSTOM METADATA FOR EXPLICIT EVENT (Example: EventType.PAUSE)
HashMap<String, Object> testPauseMap = new HashMap<>(); testPauseMap.put("key", "value"); DZEventCollector.addMetadataForAppropriateEvent(EventType.PAUSE, testPauseMap);
DELETE CUSTOM METADATA FOR EXPLICIT EVENT (Example: EventType.PAUSE)
1. DZEventCollector.clearMetadataForAppropriateEvent();
Custom Events
a. Create an Event object.
Event event = new Event("Custom_Event_Name", new JSONArray()); or Event event = new Event(String type, HashMap<String, Object> metadata);
The first constructor parameter is the event name, and the second is a list of custom metadata to be included in the event.
b. Add the event to DZEventCollector.
dzEventCollector.addCustomEvent(event);
Example:
@Override public void onSuccess(DZEventCollector dzEventCollector) { Event event = new Event("SDKLoaded", new JSONArray()); dzEventCollector.addCustomEvent(event); btnPush.setOnClickListener(v -> { try { Event event1 = new Event("btnPush", new JSONArray("[{\"customPlay\": \"true\"}] ")); dzEventCollector.addCustomEvent(event1); } catch (JSONException e) { e.printStackTrace(); } }); }
Demo application
A demo application can be found here. This can be used to test the Datazoom native Android collector classes.
Comments
0 comments
Article is closed for comments.