Version : 1.0.5
Organization : Thủ Đô Multimedia
- Introduction
- Scope
- System Requirements
- App Requirements
- Installation
- Usage
- Important Notes
- Conclusion
- References
This document provides a guide for integrating and using the SSAITracking SDK for Android applications, specifically using Media3. It includes detailed information on installation, SDK initialization, and handling necessary callbacks.
This document applies to iOS developers who want to integrate the SSAITracking SDK into their applications, including requesting IDFA access as per App Tracking Transparency requirements.
- Operating System : Android 5.0 and above
- Device : Physical device required
- Android minimum SDK: 24
- Android target SDK: 34
- Player Library: Media3
- Add Repository Sigma :
In your
rootProject/build.gradle
file, add the following repositories:
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://maven.sigma.video"
}
}
}
-
Allowed to use HTTP (unencrypted protocol) to communicate with the local server: In
rootProject/app/src/main/AndroidManifest.xml
add the following:<manifest ...> <uses-permission android:name="android.permission.INTERNET" /> <application ... android:usesCleartextTraffic="true" ...> ... </application> </manifest>
-
Add Library Media3 player (skip if you're already using a different media3 version): In your app/build.gradle file, include the following dependencies:
-
Add Sigma SSAI plugin : In your app/build.gradle file, include the following dependencies:
dependencies {
...
implementation 'com.sigma.ssai:sigma-ssai-media3-cspm:1.0.5'
...
}
- Import the SDK :
import com.tdm.adstracking.AdsTracking;
- Call the start function when your application launches :
AdsTracking.getInstance().startServer();
- Initialize the SDK with the required parameters :
AdsTracking.getInstance().init(
this,
playerView,
sourceUrl,
new ResponseInitListener() {
@Override
public void onInitFailed(String url, String msg) {
//generate source failed
}
@Override
public void onInitSuccess(String modifiUrl) {
//generate source success
}
}
);
this
: Reference to the current Activity.playerView
: The view where the video player will be displayed.sourceUrl
: String url source for the main content.
- Success Callback :
Called
onInitSuccess
when initialization succeeds; returns modified source for tracking - Failure Callback :
Called
onInitFailed
when initialization fails; returns original source url.
- Call
initPlayer()
and pass initialized player Important note: The Player passed to the AdsTracking.getInstance().initPlayer(player) function must always be a direct instance of ExoPlayer. Avoid using instances created through MediaController or any other wrapping mechanism, to ensure AdsTracking works properly with events and player state.
import androidx.media3.common.Player;
...
Player player = new ExoPlayer.Builder(this).build();
AdsTracking.getInstance().initPlayer(player);
- Play the Media Source
Use the modifi source returned by the onInitSuccess
(or originalsource returned by the onInitFailed
) callback to initialize and play the media.
Here's an example using Media3:
PlayerView playerView;
...
playerView.setPlayer(player);
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(modifiUrl));
player.setMediaItem(mediaItem);
player.prepare();
player.setPlayWhenReady(true);
To prevent memory leaks, call the destroy()
method when the activity or player is destroyed. This ensures that the ad tracking resources are cleaned up properly.
@Override
protected void onDestroy() {
AdsTracking.getInstance().destroy();
super.onDestroy();
}
Always remember to call setPlayer()
on the SDK after initializing the ExoPlayer or replacing the current item. This ensures that the SDK correctly recognizes the active video player and can effectively manage ad tracking. If you need to change the adsEndpoint
or adsParams
, it is essential to reinitialize the SDK. This ensures that the new endpoint and new params is properly configured and used for tracking.
By following the steps outlined above, you can successfully integrate and utilize the SSAITracking SDK within your application. Ensure that you handle both success and failure callbacks to provide a seamless user experience.
SSAITracking demo link: Demo