Usage (Android)
To use the SDK, you have to call the respective API.
Demo Activity
A demo activity is attached to the SDK. Unzip the file surfmeteranalytics_demo_$version.zip, and check out the MainActivity.java file to see how the app should be called. You can place this activity inside your existing app, or a new app. Just make sure you set up the dependencies correctly (see previous section).
Basic Example
In the simplest case, you need a builder for the API which can be launched in the onCreate method of your activity, and attach it to the existing ExoPlayer instance.
For example:
SurfmeterAnalytics mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
).build();
Advanced Examples
1. With Custom Metadata
You can attach custom metadata to your analytics data:
SurfmeterAnalytics mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
)
.setMetadata(new HashMap<String, String>(2) {{
put("userId", "some-user-id");
put("assetId", "some-asset-id");
}})
.build();
These can be retrieved in the dashboard, and are very useful for segmenting your data for analysis purposes.
Please make sure that if you send personal data such as customer IDs, names, or email addresses, you have the necessary consent of the user to do so.
2. With Analytics Listener
You can listen to analytics events by implementing the SurfmeterAnalyticsListener interface:
public class YourActivity extends AppCompatActivity implements SurfmeterAnalyticsListener {
private SurfmeterAnalytics mAnalytics;
private void initAnalytics() {
mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
)
.setAnalyticsListener(this)
.build();
}
@Override
public void onStateChanged(AnalyticsState state) {
Log.d("YourActivity", "Analytics state changed: " + state);
}
@Override
public void onSendingData() {
Log.d("YourActivity", "Analytics is sending data");
}
@Override
public void onError(@NonNull AnalyticsException error) {
Log.e("YourActivity", "Analytics error: " + error);
}
@Override
public void onLog(@NonNull int level, @NonNull String tag, @NonNull String message) {
Log.d("YourActivity", "Analytics log: " + message);
}
}
3. With Connection Detail Tracing
To enable detailed network connection tracing:
SurfmeterAnalytics mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
)
.enableConnectionDetailTracing()
.build();
This tracks information from the WiFi connection, in particular the (B)SSID and the IP address. If additional permissions are given (ACCESS_WIFI_STATE), we can also obtain the signal strength.
4. With Custom Sending Interval
You can customize how often the analytics data is sent:
SurfmeterAnalytics mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
)
.setSendingInterval(30) // send every 30 seconds
.build();
5. Reporting Playback Errors
The SDK automatically captures errors from ExoPlayer and sends them with the raw code of the player and a standardized SVTA2070 code. For failed HTTP requests, it also sends the HTTP status. For example, a 404 response has the SVTA code 3404.
A fatal player error is sent at once, and the session stays open for 30 seconds. If the player becomes ready again in this time, for example after a retry with prepare(), the session continues. Otherwise, or if the app finishes or releases the player in this time, the session ends as aborted with the reason playbackError. This time counts neither as play time nor as stalling.
You can also report custom errors from your application:
// Report a custom playback error
mAnalytics.onPlaybackError(
"CDN timeout after 30s", // message: human-readable error description
"cdn_error", // errorType: error category or class name
"504" // errorCode: numeric error code as a string
);
Parameters (all nullable):
message— A human-readable description of the error. Defaults to "Unknown playback error" if null.errorType— The error category, e.g."network_error","drm_error", or an ExoPlayer error code name like"ERROR_CODE_IO_NETWORK_CONNECTION_FAILED".errorCode— A numeric error code as a string, e.g."2001"or"504".
These errors are non-fatal. To report a fatal error or set the SVTA code and HTTP status, use the overload onPlaybackError(message, errorType, errorCode, svtaCode, fatal, httpStatus). Without an SVTA code, the code comes from the HTTP status, or else it is 999 (unknown).
Multiple errors can be reported between sends; they all accumulate and are included in the next data transmission.
This is useful for reporting errors that are not directly raised by ExoPlayer, such as application-level issues, DRM errors caught in your own logic, or network errors detected outside the player.
6. Content Type, Device Type and Display Size
You can set the content type of the videos, and the device type and display size used to calculate the video quality score (ITU-T P.1203):
SurfmeterAnalytics mAnalytics = new SurfmeterAnalytics.Builder(
this,
mPlayer,
"YOUR-API-KEY"
)
.setContentType("feature")
.setDeviceType("mobile")
.setDisplaySize(2400, 1080)
.build();
setContentType(String)— the type of content:"live","feature"(for example, a movie or an episode on demand),"trailer","advertisement","lab"or"unknown". It applies to all videos of this instance. If you do not set it, the SDK sets"live"for live streams and"unknown"otherwise.setDeviceType(String)—"mobile"or"pc". The device type changes the quality score, since the P.1203 model rates the same video differently on a small screen. If you do not set it, the SDK sets"mobile"on smartphones and tablets, and"pc"on all other devices, such as TVs.setDisplaySize(int width, int height)— the display size in pixels, as whole numbers greater than 0. The SDK uses this value for the whole session, instead of the size of the player's video surface. If you do not set it, the SDK uses the size of the video surface, or 1920×1080 until ExoPlayer reports it.
The SDK logs a warning and ignores invalid values, for example setContentType("vod").
The SDK also sends the type of hardware (smartphone, tablet or TV), the device vendor and model, and the screen resolution with each measurement. The device type you set does not change these values.
The THEOplayer SDK for Android has the same builder methods. There, the display size you set replaces the video size that THEOplayer reports.
Lifecycle Management
Make sure to properly handle the analytics lifecycle:
// Stop analytics when done
@Override
protected void onDestroy() {
super.onDestroy();
if (mAnalytics != null) {
mAnalytics.finish();
}
}
// Or abort with reason if needed
private void handleError() {
if (mAnalytics != null) {
mAnalytics.abort("Player error occurred");
}
}
Instrumented Usage
You can also call the demo activity with adb using the following example command:
adb shell am start -n "com.aveq.surfmeteranalyticsdemo/.MainActivity" \
--ez autoRunTest true \
--el maxTestDuration 10000 \
--es manifestUri "https://example.com/manifest.mpd"
Note that these intent parameters are directly passed to the quality test SDK; check the demo app source code for more info on how they are handled.
Finally, we provide a shell script to run an Analytics test using the above call, which waits for the test to finish and then exits. See ./run_analytics_test.sh for more info.
API Docs
Please refer to the documentation in docs for more details.