Skip to content

Commit

Permalink
rename playerDecorator to player
Browse files Browse the repository at this point in the history
  • Loading branch information
stonko1994 committed Aug 26, 2024
1 parent 8f54124 commit 1988b97
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ConvivaAnalyticsIntegration {
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
@NonNull
private final PlayerDecorator playerDecorator;
private final PlayerDecorator player;
private MetadataOverrides metadataOverrides;
private final DefaultSsaiApi ssai;

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

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

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

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

// region public methods
Expand Down Expand Up @@ -174,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 ((playerDecorator.getStreamTitle() == null)
if ((player.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 @@ -348,7 +348,7 @@ private void updateSession() {
}

private void updatePlaybackVideoData() {
HashMap<String, Object[]> playbackVideoData = playerDecorator.getPlaybackVideoData();
HashMap<String, Object[]> playbackVideoData = player.getPlaybackVideoData();
for (Map.Entry<String, Object[]> entry : playbackVideoData.entrySet()) {
convivaVideoAnalytics.reportPlaybackMetric(entry.getKey(), entry.getValue());
if (ssai.isAdBreakActive()) {
Expand All @@ -362,8 +362,8 @@ private void createContentMetadata() {
if (overriddenAssetName != null) {
contentMetadataBuilder.setAssetName(overriddenAssetName);
} else {
if (playerDecorator.getStreamTitle() != null) {
contentMetadataBuilder.setAssetName(playerDecorator.getStreamTitle());
if (player.getStreamTitle() != null) {
contentMetadataBuilder.setAssetName(player.getStreamTitle());
} else {
Log.w(TAG, "No asset name provided for content metadata.");
}
Expand All @@ -377,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, playerDecorator.getStreamType());
customInternTags.put(STREAM_TYPE, player.getStreamType());
customInternTags.put(INTEGRATION_VERSION, BuildConfig.VERSION_NAME);
contentMetadataBuilder.setCustom(customInternTags);

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

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

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

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

private void detachBitmovinEventListeners() {
playerDecorator.withEventEmitter(bitmovinPlayer -> {
player.withEventEmitter(bitmovinPlayer -> {
bitmovinPlayer.off(SourceEvent.Unloaded.class, onSourceUnloadedListener);
bitmovinPlayer.off(PlayerEvent.Error.class, onPlayerErrorListener);
bitmovinPlayer.off(SourceEvent.Error.class, onSourceErrorListener);
Expand Down Expand Up @@ -604,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 (playerDecorator.isPaused()) {
if (player.isPaused()) {
state = ConvivaSdkConstants.PlayerState.PAUSED;
}
transitionState(state);
Expand Down Expand Up @@ -650,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 (playerDecorator.isPlaying()) {
if (player.isPlaying()) {
state = ConvivaSdkConstants.PlayerState.PLAYING;
}
transitionState(state);
Expand Down Expand Up @@ -774,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 == playerDecorator.getDuration()) {
} else if (timeOffset == player.getDuration()) {
adPosition = ConvivaSdkConstants.AdPosition.POSTROLL;
}
return adPosition;
Expand Down Expand Up @@ -815,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, playerDecorator.getPlayHeadTimeMillis());
convivaVideoAnalytics.reportPlaybackMetric(ConvivaSdkConstants.PLAYBACK.PLAY_HEAD_TIME, player.getPlayHeadTimeMillis());
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ public class DefaultSsaiApi implements SsaiApi {
private static final String TAG = "DefaultSsaiApi";
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
private final PlayerDecorator playerDecorator;
private final PlayerDecorator player;

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

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

private void reportInitialAdMetrics() {
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, playerDecorator.getPlayerState());
HashMap<String, Object[]> playbackVideoData = playerDecorator.getPlaybackVideoData();
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, player.getPlayerState());
HashMap<String, Object[]> playbackVideoData = player.getPlaybackVideoData();
for (Map.Entry<String, Object[]> entry : playbackVideoData.entrySet()) {
convivaAdAnalytics.reportAdMetric(entry.getKey(), entry.getValue());
}
Expand Down

0 comments on commit 1988b97

Please sign in to comment.