Skip to content

Commit

Permalink
rename PlayerAdapter to PlayerDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
stonko1994 committed Aug 26, 2024
1 parent efc76ad commit 8f54124
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.bitmovin.player.api.event.EventListener;
import com.bitmovin.player.api.event.PlayerEvent;
import com.bitmovin.player.api.event.SourceEvent;
import com.bitmovin.player.api.source.Source;
import com.bitmovin.player.api.source.SourceConfig;
import com.conviva.sdk.ConvivaAdAnalytics;
import com.conviva.sdk.ConvivaAnalytics;
import com.conviva.sdk.ConvivaExperienceAnalytics;
Expand All @@ -40,7 +38,7 @@ public class ConvivaAnalyticsIntegration {
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
@NonNull
private final PlayerAdapter playerAdapter;
private final PlayerDecorator playerDecorator;
private MetadataOverrides metadataOverrides;
private final DefaultSsaiApi ssai;

Expand Down Expand Up @@ -90,7 +88,7 @@ public ConvivaAnalyticsIntegration(Player player,
ConvivaAdAnalytics adAnalytics,
DefaultSsaiApi ssai
) {
playerAdapter = new DefaultPlayerAdapter(player);
playerDecorator = new DefaultPlayerDecorator(player);
Map<String, Object> settings = new HashMap<>();
if (config.getGatewayUrl() != null || config.isDebugLoggingEnabled()) {
if (config.getGatewayUrl() != null) {
Expand All @@ -114,7 +112,7 @@ public ConvivaAnalyticsIntegration(Player player,
}

if (ssai == null) {
this.ssai = new DefaultSsaiApi(convivaVideoAnalytics, convivaAdAnalytics, playerAdapter);
this.ssai = new DefaultSsaiApi(convivaVideoAnalytics, convivaAdAnalytics, playerDecorator);
} else {
this.ssai = ssai;
}
Expand All @@ -128,7 +126,7 @@ private void setUpAdAnalyticsCallback() {
@Override
public void update() {
if (isAdActive()) {
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAY_HEAD_TIME, ((long) (playerAdapter.getPlayHeadTimeMillis())));
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAY_HEAD_TIME, ((long) (playerDecorator.getPlayHeadTimeMillis())));
}
}

Expand All @@ -139,7 +137,7 @@ public void update(String s) {
}

private boolean isAdActive() {
return playerAdapter.isAd() || ssai.isAdBreakActive();
return playerDecorator.isAd() || ssai.isAdBreakActive();
}

// region public methods
Expand Down Expand Up @@ -176,7 +174,7 @@ public void sendCustomPlaybackEvent(String name, Map<String, Object> attributes)
* If no source was loaded this method will throw an error.
*/
public void initializeSession() throws ConvivaAnalyticsException {
if ((playerAdapter.getStreamTitle() == null)
if ((playerDecorator.getStreamTitle() == null)
&& this.contentMetadataBuilder.getAssetName() == null) {
throw new ConvivaAnalyticsException(
"AssetName is missing. Load player source (with Title) first or set assetName via updateContentMetadata"
Expand Down Expand Up @@ -350,7 +348,7 @@ private void updateSession() {
}

private void updatePlaybackVideoData() {
HashMap<String, Object[]> playbackVideoData = playerAdapter.getPlaybackVideoData();
HashMap<String, Object[]> playbackVideoData = playerDecorator.getPlaybackVideoData();
for (Map.Entry<String, Object[]> entry : playbackVideoData.entrySet()) {
convivaVideoAnalytics.reportPlaybackMetric(entry.getKey(), entry.getValue());
if (ssai.isAdBreakActive()) {
Expand All @@ -364,8 +362,8 @@ private void createContentMetadata() {
if (overriddenAssetName != null) {
contentMetadataBuilder.setAssetName(overriddenAssetName);
} else {
if (playerAdapter.getStreamTitle() != null) {
contentMetadataBuilder.setAssetName(playerAdapter.getStreamTitle());
if (playerDecorator.getStreamTitle() != null) {
contentMetadataBuilder.setAssetName(playerDecorator.getStreamTitle());
} else {
Log.w(TAG, "No asset name provided for content metadata.");
}
Expand All @@ -379,18 +377,18 @@ private void buildDynamicContentMetadata() {
// streamType could be missing at time of session initialization
// as source information could be unavailable at that time
Map<String, String> customInternTags = new HashMap<>();
customInternTags.put(STREAM_TYPE, playerAdapter.getStreamType());
customInternTags.put(STREAM_TYPE, playerDecorator.getStreamType());
customInternTags.put(INTEGRATION_VERSION, BuildConfig.VERSION_NAME);
contentMetadataBuilder.setCustom(customInternTags);

if (playerAdapter.isLive()) {
if (playerDecorator.isLive()) {
contentMetadataBuilder.setStreamType(ConvivaSdkConstants.StreamType.LIVE);
} else {
contentMetadataBuilder.setStreamType(ConvivaSdkConstants.StreamType.VOD);
contentMetadataBuilder.setDuration((int) playerAdapter.getDuration());
contentMetadataBuilder.setDuration((int) playerDecorator.getDuration());
}

contentMetadataBuilder.setStreamUrl(playerAdapter.getStreamUrl());
contentMetadataBuilder.setStreamUrl(playerDecorator.getStreamUrl());
}

private void internalEndSession() {
Expand All @@ -406,7 +404,7 @@ private void internalEndSession() {
// endregion

private void attachBitmovinEventListeners() {
playerAdapter.withEventEmitter(eventEmitter -> {
playerDecorator.withEventEmitter(eventEmitter -> {
eventEmitter.on(SourceEvent.Unloaded.class, onSourceUnloadedListener);
eventEmitter.on(PlayerEvent.Error.class, onPlayerErrorListener);
eventEmitter.on(SourceEvent.Error.class, onSourceErrorListener);
Expand Down Expand Up @@ -446,7 +444,7 @@ private void attachBitmovinEventListeners() {
}

private void detachBitmovinEventListeners() {
playerAdapter.withEventEmitter(bitmovinPlayer -> {
playerDecorator.withEventEmitter(bitmovinPlayer -> {
bitmovinPlayer.off(SourceEvent.Unloaded.class, onSourceUnloadedListener);
bitmovinPlayer.off(PlayerEvent.Error.class, onPlayerErrorListener);
bitmovinPlayer.off(SourceEvent.Error.class, onSourceErrorListener);
Expand Down Expand Up @@ -606,7 +604,7 @@ public void onEvent(PlayerEvent.StallEnded stallEndedEvent) {
new Handler().postDelayed(() -> {
Log.d(TAG, "[Player Event] StallEnded");
ConvivaSdkConstants.PlayerState state = ConvivaSdkConstants.PlayerState.PLAYING;
if (playerAdapter.isPaused()) {
if (playerDecorator.isPaused()) {
state = ConvivaSdkConstants.PlayerState.PAUSED;
}
transitionState(state);
Expand Down Expand Up @@ -652,7 +650,7 @@ public void setSeekEnd() {
// Notify of seek buffering complete at this stage.
Log.d(TAG, "[Player Event] Update state after buffering");
ConvivaSdkConstants.PlayerState state = ConvivaSdkConstants.PlayerState.PAUSED;
if (playerAdapter.isPlaying()) {
if (playerDecorator.isPlaying()) {
state = ConvivaSdkConstants.PlayerState.PLAYING;
}
transitionState(state);
Expand Down Expand Up @@ -776,7 +774,7 @@ private ConvivaSdkConstants.AdPosition getAdPosition(double timeOffset) {
ConvivaSdkConstants.AdPosition adPosition = ConvivaSdkConstants.AdPosition.MIDROLL;
if (timeOffset == 0.0) {
adPosition = ConvivaSdkConstants.AdPosition.PREROLL;
} else if (timeOffset == playerAdapter.getDuration()) {
} else if (timeOffset == playerDecorator.getDuration()) {
adPosition = ConvivaSdkConstants.AdPosition.POSTROLL;
}
return adPosition;
Expand Down Expand Up @@ -817,7 +815,7 @@ public void onEvent(PlayerEvent.AdError adError) {
@Override
public void onEvent(PlayerEvent.TimeChanged timeChangedEvent) {
if (isSessionActive) {
convivaVideoAnalytics.reportPlaybackMetric(ConvivaSdkConstants.PLAYBACK.PLAY_HEAD_TIME, playerAdapter.getPlayHeadTimeMillis());
convivaVideoAnalytics.reportPlaybackMetric(ConvivaSdkConstants.PLAYBACK.PLAY_HEAD_TIME, playerDecorator.getPlayHeadTimeMillis());
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import java.util.HashMap;

public class DefaultPlayerAdapter implements PlayerAdapter {
public class DefaultPlayerDecorator implements PlayerDecorator {
private final Player player;

public DefaultPlayerAdapter(Player player) {
public DefaultPlayerDecorator(Player player) {
this.player = player;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.HashMap;

public interface PlayerAdapter {
public interface PlayerDecorator {
ConvivaSdkConstants.PlayerState getPlayerState();

HashMap<String, Object[]> getPlaybackVideoData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.util.Log;

import com.bitmovin.analytics.conviva.ConvivaAnalyticsIntegration;
import com.bitmovin.analytics.conviva.PlayerAdapter;
import com.bitmovin.analytics.conviva.PlayerDecorator;
import com.conviva.sdk.ConvivaAdAnalytics;
import com.conviva.sdk.ConvivaSdkConstants;
import com.conviva.sdk.ConvivaVideoAnalytics;
Expand All @@ -16,12 +16,12 @@ public class DefaultSsaiApi implements SsaiApi {
private static final String TAG = "DefaultSsaiApi";
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
private final PlayerAdapter playerAdapter;
private final PlayerDecorator playerDecorator;

public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlayerAdapter playerAdapter) {
public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlayerDecorator playerDecorator) {
this.convivaVideoAnalytics = convivaVideoAnalytics;
this.convivaAdAnalytics = convivaAdAnalytics;
this.playerAdapter = playerAdapter;
this.playerDecorator = playerDecorator;
}

private boolean isAdBreakActive = false;
Expand Down Expand Up @@ -77,8 +77,8 @@ public void reportAdStarted(AdInfo adInfo) {
}

private void reportInitialAdMetrics() {
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, playerAdapter.getPlayerState());
HashMap<String, Object[]> playbackVideoData = playerAdapter.getPlaybackVideoData();
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, playerDecorator.getPlayerState());
HashMap<String, Object[]> playbackVideoData = playerDecorator.getPlaybackVideoData();
for (Map.Entry<String, Object[]> entry : playbackVideoData.entrySet()) {
convivaAdAnalytics.reportAdMetric(entry.getKey(), entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bitmovin.analytics.conviva.ssai

import android.util.Log
import com.bitmovin.analytics.conviva.PlayerAdapter
import com.bitmovin.analytics.conviva.PlayerDecorator
import com.conviva.sdk.ConvivaAdAnalytics
import com.conviva.sdk.ConvivaSdkConstants
import com.conviva.sdk.ConvivaVideoAnalytics
Expand Down Expand Up @@ -30,13 +30,13 @@ import strikt.assertions.isTrue
class DefaultSsaiApiTest {
private val videoAnalytics: ConvivaVideoAnalytics = mockk(relaxed = true)
private val adAnalytics: ConvivaAdAnalytics = mockk()
private val playerAdapter = mockk<PlayerAdapter>()
private val playerDecorator = mockk<PlayerDecorator>()
private lateinit var ssaiApi: DefaultSsaiApi

@Before
fun beforeTest() {
every { playerAdapter.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING
every { playerAdapter.playbackVideoData } returns hashMapOf<String, Array<Any>>(
every { playerDecorator.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING
every { playerDecorator.playbackVideoData } returns hashMapOf<String, Array<Any>>(
ConvivaSdkConstants.PLAYBACK.BITRATE to arrayOf(1),
ConvivaSdkConstants.PLAYBACK.RESOLUTION to arrayOf(800, 1600),
ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE to arrayOf(60),
Expand All @@ -55,13 +55,13 @@ class DefaultSsaiApiTest {
ssaiApi = DefaultSsaiApi(
videoAnalytics,
adAnalytics,
playerAdapter,
playerDecorator,
)
}

@After
fun afterTest() {
clearMocks(videoAnalytics, adAnalytics, playerAdapter)
clearMocks(videoAnalytics, adAnalytics, playerDecorator)
}


Expand Down Expand Up @@ -132,7 +132,7 @@ class DefaultSsaiApiTest {

@Test
fun `reports ad playback state playing to conviva when ad starts while paused`() {
every { playerAdapter.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED
every { playerDecorator.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED

ssaiApi.reportAdBreakStarted()
ssaiApi.reportAdStarted(SsaiApi.AdInfo())
Expand All @@ -147,7 +147,7 @@ class DefaultSsaiApiTest {

@Test
fun `reports ad playback state buffering to conviva when ad starts while stalling`() {
every { playerAdapter.playerState } returns
every { playerDecorator.playerState } returns
ConvivaSdkConstants.PlayerState.BUFFERING

ssaiApi.reportAdBreakStarted()
Expand Down

0 comments on commit 8f54124

Please sign in to comment.