Yospace is a server-side ad insertion (SSAI) service that includes a Yospace Server at the head-end (controlling a SpotX ad server). To simplify the operations and the ad insertion, Yospace provides an Android client to communicate between the Yospace head-end on one side and the application and its player on the other. The Yospace client consists of some libraries (fetched through the build.gradle script) and some Java classes (slightly modified to work with the CONNECT SDK).
The yospace example code demonstrates how an application can be set up with the CONNECT Player SDK 5 as its player utilising the Yospace client and server.
The application can limit users' available functions like pause and rewind based on playerPolicyImpl
passed down from the Yospace server. It uses the player policy based on playback duration, isLive
, streamURL
and other such values to limit user actions and place adverts from the server within the timeline. Advert placement is normally decided by header information, what happens on click, and if the advert can be skipped.
The application is responsible for:
Example code
Creating Yospace
Click here to see the example code.
To initialise Yospace, you must first create a PlayerAdapter
which is constructed based on if the stream is live or not.
JAVA
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onMoveToForeground() {
Log.d(Constant.getLogTag(), "App moved to foreground");
setupYospace();
}
...
private void setupYospace() {
// Initialise Yospace infrastructures
PlayerAdapter adapter = mIsLive ? new PlayerAdapterLive(this, null) : new PlayerAdapter(this, mTimeline);
initialiseYospace(adapter);
if(mIsLive) {
initialisePlayer(mStreamUrl, adapter);
}
}
Create a listener.
JAVA
//Initialise Yospace infrastructure for non-linear playback
private void initialiseYospace(final PlayerAdapter adapter) {
EventListener<Session> yoSpaceListener = event -> {
// Retrieve the initialised session
mSession = event.getPayload();
switch (mSession.getState()) {
case INITIALISED:
adapter.setSession(mSession);
// Instantiate a LogAnalyticEventListener to make Analytic events visible in the log
mSession.addAnalyticListener(MainActivity.this);
mSession.setPlayerPolicy(new PlayerPolicyImpl());
if (!mIsLive) {
runOnUiThread(
() -> {
// Initialise ExoPlayer infrastructure
initialisePlayer(mSession.getPlayerUrl(), adapter);
// update the timeline for vod
SessionNonLinear session = (SessionNonLinear) (mSession);
mTimeline.UpdateTimeline(session.getAdBreaks(), 0, session.getDuration());
}
);
}
return;
case NO_ANALYTICS:
Log.i(Constant.getLogTag(),
"initialiseYospace - Video URL does not refer to a Yospace stream, no analytics session created");
return;
case NOT_INITIALISED:
Log.e(Constant.getLogTag(), "initialiseYospace - Failed to initialise analytics session");
}
};
if (mIsLive) {
Session.SessionProperties properties = new Session.SessionProperties(VIDEO_URL_LIVE).userAgent(USER_AGENT);
properties.addDebugFlags(YoLog.DEBUG_POLLING | YoLog.DEBUG_ID3TAG | YoLog.DEBUG_PARSING | YoLog.DEBUG_REPORTS | YoLog.DEBUG_HTTP | YoLog.DEBUG_RAW_XML);
SessionFactory factory = SessionFactory.createForLiveWithThread(yoSpaceListener, properties);
mStreamUrl = factory.getPlayerUrl();
} else {
Session.SessionProperties properties = new Session.SessionProperties(VIDEO_URL_VOD).userAgent(USER_AGENT);
properties.addDebugFlags(YoLog.DEBUG_PARSING | YoLog.DEBUG_POLLING | YoLog.DEBUG_HEARTBEAT_STATE);
SessionNonLinear.create(yoSpaceListener, properties);
}
}
With this, a Yospace sessionFactory
is created based on if the video is live or VOD and the parameters passed in by the USER_AGENT
.
JAVA
/**
* User agent, used when making calls for video content and adverts
*/
public static final String USER_AGENT = "YospaceSamplePlayer";
Implementing advert analytics
When constructing the Activity that contains Yospace, you may want to implement AnalyticsEventListener
which has event listeners for things like onAdvetEnd
and onTimelineUpdateReceived
to implement your adverts.
Click here for an example of how to implement this interface to add functionality.
JAVA
public interface AnalyticEventListener {
void onAdvertBreakEnd(AdBreak var1);
void onAdvertBreakStart(AdBreak var1);
void onAdvertEnd(Advert var1);
void onAdvertStart(Advert var1);
void onTimelineUpdateReceived(VmapPayload var1);
void onTrackingUrlCalled(Advert var1, String var2, String var3);
void onVastReceived(VastPayload var1);
}