Skip to content

Commit

Permalink
Merge pull request #79 from bitmovin/feature/introduce-player-adapter
Browse files Browse the repository at this point in the history
Merge `PlaybackInfoProvider` and `PlayerHelper` into `PlayerDecorator`
  • Loading branch information
stonko1994 authored Aug 27, 2024
2 parents 1c6d2f5 + 252f8cd commit 4614d63
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 177 deletions.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.bitmovin.analytics.conviva.ssai;
package com.bitmovin.analytics.conviva;

import com.bitmovin.analytics.conviva.helper.WithEventEmitter;
import com.bitmovin.player.api.Player;
import com.bitmovin.player.api.media.video.quality.VideoQuality;
import com.conviva.sdk.ConvivaSdkConstants;

import java.util.HashMap;

public class DefaultPlaybackInfoProvider implements PlaybackInfoProvider {
public class DefaultPlayerDecorator implements PlayerDecorator {
private final Player player;

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

Expand Down Expand Up @@ -44,4 +45,63 @@ public HashMap<String, Object[]> getPlaybackVideoData() {
}
return videoData;
}

@Override
public String getStreamTitle() {
return player.getSource() == null ? null : player.getSource().getConfig().getTitle();
}

@Override
public String getStreamType() {
return player.getSource() == null ? null : player.getSource().getConfig().getType().name();
}

@Override
public String getStreamUrl() {
return player.getSource() == null ? null : player.getSource().getConfig().getUrl();
}


@Override
public boolean isAd() {
return player.isAd();
}

@Override
public boolean isLive() {
return player.isLive();
}

@Override
public boolean isPaused() {
return player.isPaused();
}

@Override
public boolean isPlaying() {
return player.isPlaying();
}

@Override
public double getDuration() {
return player.getDuration();
}

@Override
public long getPlayHeadTimeMillis() {
if (player.isLive()) {
double playerTimeShiftMax = player.getMaxTimeShift();
double playerTimeShift = player.getTimeShift();
long playerDurationMs = -(Math.round(playerTimeShiftMax * 1000));
return playerDurationMs - -(Math.round(playerTimeShift * 1000));
} else {
double currentTime = player.getCurrentTime();
return (long) (currentTime * 1000);
}
}

@Override
public void withEventEmitter(WithEventEmitter withEventEmitter) {
withEventEmitter.call(player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.bitmovin.analytics.conviva;

import com.bitmovin.analytics.conviva.helper.WithEventEmitter;
import com.conviva.sdk.ConvivaSdkConstants;

import java.util.HashMap;

public interface PlayerDecorator {
ConvivaSdkConstants.PlayerState getPlayerState();

HashMap<String, Object[]> getPlaybackVideoData();

boolean isAd();

String getStreamTitle();

String getStreamType();

String getStreamUrl();

long getPlayHeadTimeMillis();

boolean isLive();

double getDuration();

void withEventEmitter(WithEventEmitter withEventEmitter);

boolean isPaused();

boolean isPlaying();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bitmovin.analytics.conviva.helper;

import com.bitmovin.player.api.event.Event;
import com.bitmovin.player.api.event.JavaEventEmitter;

public interface WithEventEmitter {
void call(JavaEventEmitter<Event> player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.util.Log;

import com.bitmovin.analytics.conviva.ConvivaAnalyticsIntegration;
import com.bitmovin.analytics.conviva.PlayerDecorator;
import com.conviva.sdk.ConvivaAdAnalytics;
import com.conviva.sdk.ConvivaSdkConstants;
import com.conviva.sdk.ConvivaVideoAnalytics;
Expand All @@ -15,9 +16,13 @@ public class DefaultSsaiApi implements SsaiApi {
private static final String TAG = "DefaultSsaiApi";
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
private final PlaybackInfoProvider player;
private final PlayerDecorator player;

public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlaybackInfoProvider player) {
public DefaultSsaiApi(
ConvivaVideoAnalytics convivaVideoAnalytics,
ConvivaAdAnalytics convivaAdAnalytics,
PlayerDecorator player
) {
this.convivaVideoAnalytics = convivaVideoAnalytics;
this.convivaAdAnalytics = convivaAdAnalytics;
this.player = player;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bitmovin.analytics.conviva.ssai

import android.util.Log
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 @@ -29,13 +30,13 @@ import strikt.assertions.isTrue
class DefaultSsaiApiTest {
private val videoAnalytics: ConvivaVideoAnalytics = mockk(relaxed = true)
private val adAnalytics: ConvivaAdAnalytics = mockk()
private val playbackInfoProvider = mockk<PlaybackInfoProvider>()
private val playerDecorator = mockk<PlayerDecorator>()
private lateinit var ssaiApi: DefaultSsaiApi

@Before
fun beforeTest() {
every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING
every { playbackInfoProvider.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 @@ -52,15 +53,15 @@ class DefaultSsaiApiTest {
}

ssaiApi = DefaultSsaiApi(
videoAnalytics,
adAnalytics,
playbackInfoProvider,
videoAnalytics,
adAnalytics,
playerDecorator,
)
}

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


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

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

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

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

ssaiApi.reportAdBreakStarted()
Expand Down

0 comments on commit 4614d63

Please sign in to comment.