Skip to content

Commit

Permalink
Merge branch 'develop' into fix/reporting-lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
testcenter committed Aug 28, 2024
2 parents d7a2a00 + c15f5b6 commit 6cc1450
Show file tree
Hide file tree
Showing 18 changed files with 769 additions and 350 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Possibility to start session tracking without a `Player` instance
- `ConvivaAnalyticsIntegration(customerKey:config:)` constructor without a `Player`
- `ConvivaAnalyticsIntegration.attachPlayer()` to attach the `Player` at a later point in the session life-cycle

### Removed
- Unintentionally public initializers from `ConvivaAnalyticsIntegration` which were not intended to be public and only meant for testing

## 2.6.0 - 2024-08-13
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.bitmovin.analytics.convivaanalyticsexample;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Switch;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bitmovin.analytics.conviva.ConvivaAnalyticsException;
import com.bitmovin.analytics.conviva.ConvivaAnalyticsIntegration;
import com.bitmovin.analytics.conviva.ConvivaConfig;
import com.bitmovin.analytics.conviva.MetadataOverrides;
Expand All @@ -27,21 +30,27 @@
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "Example";

// UI
private Button pauseTrackingButton;
private Button resumeTrackingButton;
private Button releaseButton;
private Button createButton;
private Button sendCustomEventButton;
private Button startSessionButton;
private Switch includeAdsSwitch;

// Conviva
private static final String customerKey = "YOUR-CUSTOMER-KEY";
private static String gatewayUrl; // Set only in debug mode
@Nullable
private ConvivaAnalyticsIntegration convivaAnalyticsIntegration;

// Player
@Nullable
private Player bitmovinPlayer;
@Nullable
private PlayerView bitmovinPlayerView;

@Override
Expand All @@ -54,10 +63,12 @@ protected void onCreate(Bundle savedInstanceState) {
resumeTrackingButton.setOnClickListener(this);
releaseButton = findViewById(R.id.release_button);
releaseButton.setOnClickListener(this);
createButton = findViewById(R.id.create_button);
createButton = findViewById(R.id.create_player_button);
createButton.setOnClickListener(this);
sendCustomEventButton = findViewById(R.id.custom_event_button);
sendCustomEventButton.setOnClickListener(this);
startSessionButton = findViewById(R.id.start_session_button);
startSessionButton.setOnClickListener(this);
includeAdsSwitch = findViewById(R.id.include_ads_switch);

this.setupBitmovinPlayer();
Expand All @@ -73,40 +84,12 @@ protected void setupBitmovinPlayer() {
LinearLayout playerUIView = this.findViewById(R.id.bitmovinPlayerUIView);
playerUIView.addView(bitmovinPlayerView);

// Create your ConvivaConfig object
ConvivaConfig convivaConfig = new ConvivaConfig();

// Set only in debug mode
if (gatewayUrl != null) {
convivaConfig.setGatewayUrl(gatewayUrl);
if (convivaAnalyticsIntegration == null) {
convivaAnalyticsIntegration = setupConvivaAnalytics(bitmovinPlayer);
} else {
convivaAnalyticsIntegration.attachPlayer(bitmovinPlayer);
}

// Add optional parameters
convivaConfig.setDebugLoggingEnabled(true);

// Create ConvivaAnalytics
convivaAnalyticsIntegration = new ConvivaAnalyticsIntegration(
bitmovinPlayer,
customerKey,
getApplicationContext(),
convivaConfig);

MetadataOverrides metadata = new MetadataOverrides();
metadata.setApplicationName("Bitmovin Android Conviva integration example app");
metadata.setViewerId("awesomeViewerId");

Map<String, Object> standardTags = new HashMap<>();
standardTags.put("c3.cm.contentType", "VOD");
metadata.setAdditionalStandardTags(standardTags);

Map<String, String> customTags = new HashMap<>();
customTags.put("custom_tag", "Episode");
metadata.setCustom(customTags);

metadata.setImaSdkVersion("3.31.0");

convivaAnalyticsIntegration.updateContentMetadata(metadata);

// load source using the created source configuration
bitmovinPlayer.load(buildSourceConfiguration());
}
Expand All @@ -118,6 +101,8 @@ private PlayerConfig buildPlayerConfiguration() {
playerConfiguration.setAdvertisingConfig(buildAdConfiguration());
}

playerConfiguration.getPlaybackConfig().setAutoplayEnabled(true);

return playerConfiguration;
}

Expand Down Expand Up @@ -145,42 +130,132 @@ private AdvertisingConfig buildAdConfiguration() {
@Override
protected void onStart() {
super.onStart();
bitmovinPlayerView.onStart();
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onStart();
}
}

@Override
protected void onResume() {
super.onResume();
bitmovinPlayerView.onResume();
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onResume();
}
}

@Override
protected void onPause() {
super.onPause();
bitmovinPlayerView.onPause();
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onStop();
}
}

@Override
protected void onStop() {
super.onStop();
bitmovinPlayerView.onStop();
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onStop();
}
}

@Override
protected void onDestroy() {
super.onDestroy();
bitmovinPlayerView.onDestroy();
convivaAnalyticsIntegration.release();
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onDestroy();
}
if (convivaAnalyticsIntegration != null) {
convivaAnalyticsIntegration.release();
}
}

private void tearDownPlayer() {
convivaAnalyticsIntegration.release();
ViewGroup parent = (ViewGroup) bitmovinPlayerView.getParent();
if (convivaAnalyticsIntegration != null) {
convivaAnalyticsIntegration.release();
convivaAnalyticsIntegration = null;
}
ViewGroup parent = null;
if (bitmovinPlayerView != null) {
parent = (ViewGroup) bitmovinPlayerView.getParent();
}
if (parent != null) {
parent.removeView(bitmovinPlayerView);
}
bitmovinPlayer.destroy();
bitmovinPlayerView.onDestroy();
if (bitmovinPlayer != null) {
bitmovinPlayer.destroy();
}
if (bitmovinPlayerView != null) {
bitmovinPlayerView.onDestroy();
}
bitmovinPlayer = null;
}

private void startSession() {
ConvivaAnalyticsIntegration convivaAnalyticsIntegration = setupConvivaAnalytics(bitmovinPlayer);
convivaAnalyticsIntegration.updateContentMetadata(buildMetadataOverrides("Art of Motion"));
try {
convivaAnalyticsIntegration.initializeSession();

this.convivaAnalyticsIntegration = convivaAnalyticsIntegration;
} catch (ConvivaAnalyticsException e) {
Log.d(TAG, "ConvivaAnalytics initialization failed with error: " + e);
}
}

private ConvivaAnalyticsIntegration setupConvivaAnalytics(@Nullable Player player) {
// Create your ConvivaConfig object
ConvivaConfig convivaConfig = new ConvivaConfig();

// Set only in debug mode
if (gatewayUrl != null) {
convivaConfig.setGatewayUrl(gatewayUrl);
}

ConvivaAnalyticsIntegration convivaAnalyticsIntegration = null;
// Add optional parameters
convivaConfig.setDebugLoggingEnabled(true);

if (player != null) {
convivaAnalyticsIntegration = new ConvivaAnalyticsIntegration(
player,
customerKey,
getApplicationContext(),
convivaConfig
);
} else {
convivaAnalyticsIntegration = new ConvivaAnalyticsIntegration(
customerKey,
getApplicationContext(),
convivaConfig
);
}

convivaAnalyticsIntegration.updateContentMetadata(buildMetadataOverrides(null));

return convivaAnalyticsIntegration;
}

private MetadataOverrides buildMetadataOverrides(@Nullable String assetName) {
MetadataOverrides metadata = new MetadataOverrides();
metadata.setApplicationName("Bitmovin Android Conviva integration example app");
metadata.setViewerId("awesomeViewerId");

Map<String, Object> standardTags = new HashMap<>();
standardTags.put("c3.cm.contentType", "VOD");
metadata.setAdditionalStandardTags(standardTags);

Map<String, String> customTags = new HashMap<>();
customTags.put("custom_tag", "Episode");
metadata.setCustom(customTags);

metadata.setImaSdkVersion("3.31.0");

if (assetName != null) {
metadata.setAssetName(assetName);
}

return metadata;
}

@Override
Expand All @@ -192,11 +267,19 @@ public void onClick(View v) {
} else if (v == sendCustomEventButton) {
Map<String, Object> eventAttributes = new HashMap<>();
eventAttributes.put("Some", "Attributes");
this.convivaAnalyticsIntegration.sendCustomPlaybackEvent("Custom Event", eventAttributes);
if (this.convivaAnalyticsIntegration != null) {
this.convivaAnalyticsIntegration.sendCustomPlaybackEvent("Custom Event", eventAttributes);
}
} else if (v == pauseTrackingButton) {
this.convivaAnalyticsIntegration.pauseTracking(false);
if (this.convivaAnalyticsIntegration != null) {
this.convivaAnalyticsIntegration.pauseTracking(false);
}
} else if (v == resumeTrackingButton) {
this.convivaAnalyticsIntegration.resumeTracking();
if (this.convivaAnalyticsIntegration != null) {
this.convivaAnalyticsIntegration.resumeTracking();
}
} else if (v == startSessionButton) {
this.startSession();
}
}
}
24 changes: 16 additions & 8 deletions ConvivaExampleApp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
android:keepScreenOn="true"
tools:context=".MainActivity">

<Button
android:id="@+id/start_session_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/start_session"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/custom_event_button"
app:layout_constraintTop_toTopOf="@+id/custom_event_button" />

<LinearLayout
android:id="@+id/bitmovinPlayerUIView"
android:layout_width="match_parent"
Expand Down Expand Up @@ -46,15 +58,13 @@

<Button
android:id="@+id/custom_event_button"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/send_custom_event"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/create_player_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/release_button" />

Expand All @@ -63,18 +73,16 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/release"
app:layout_constraintEnd_toStartOf="@+id/create_button"
app:layout_constraintEnd_toStartOf="@+id/create_player_button"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pause_tracking_button" />

<Button
android:id="@+id/create_button"
android:id="@+id/create_player_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand Down
1 change: 1 addition & 0 deletions ConvivaExampleApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="release">Release</string>
<string name="create">Create</string>
<string name="include_ads">Include Ads</string>
<string name="start_session">Start Session</string>
</resources>
Loading

0 comments on commit 6cc1450

Please sign in to comment.