Server-side ad insertion
To test this feature and view the example code, please see the (5.33.x) Android SDK 5 Example Code Quick Start guide.
Server-side ad insertion is a method where advert setup is inserted into the OTT stream manifest during or after the encoding process in conjunction with an ad server. The ssai example code demonstrates how an application can:
Extract DASH manifest (metadata) whenever a new DASH MPD file is present.
Parse the metadata and look for tags and patterns that indicate when to insert the adverts.
This example only shows how to extract the advert information but does not perform the ad insertion, as there is no specific ad server against it. The application inserts advertisements into the OTVVideoView
using metadata in the MPD using the CustomMetadataParser class attached to the videoView
via the CustomMetadataListener
.
Prerequisites
A content server configured to inject advert tags into a DASH manifest.
Example code
The Java source code contains the SSAI package that simplifies configuration and access to an ad-server, as well as playback and display of the adverts. The following instructions show you how to create and attach to the OTVVideoView
to use the CustomMetadataListener
.
CustomMetadataListener metadataListener = periods -> {
//actions to be performed with the new ad periods such as updating views or removing rewind/fast-forward control etc.
};
CustomMetadataParser parser = new CustomMetadataParser();
parser.setCustomMetadataListener(metadataListener);
mOTVVideoView.addOTVMetadataListener(parser.getOTVMetadataListener());
The CustomMetadataParser
is implemented within the CustomMetadataListener
. A list of strings containing information about the adverts is parsed from the MPD if the related tag for SSAI is found (written here as SSAI_DASH_TAG
).
private OTVMetadataListener mOTVMetadataListener = xMetadata -> {
if (xMetadata.contains(SSAI_DASH_TAG)) {
List<String> period = parse(xMetadata);
if (mCustomMetadataListener != null && !period.isEmpty()) {
mCustomMetadataListener.newMPDAdUpdate(period);
}
}
};