Skip to main content

Ad bookmarks

This guide shows how to implement bookmarking when using the ad insertion for video-on-demand (VOD) streams. This assumes a working ad insertion implementation, such as the one presented in Setup ad insertion.

Store a bookmark position

When playing a VOD with ads, number and position could change over time. It is necessary to take ads into account when storing a position for a later playback. The lib is providing a create a bookmark position API that translate the current position with ads to a position without ads and this value can be saved into the app.

public class PlaybackActivity extends Activity {

private StreamingSession mSession;

protected void onPause() {
// Generate the bookmark position with SmartLib
long bookmarkPosition = mSession.getPositionForBookmark();

// Store the position in your custom app storage
mAppStorage.storePosition(mContentId, bookmarkPosition);


Restore a bookmarked position

Load the bookmark when re-requesting a stream. To ensure that the restore a bookmark position API will return the correct result, call it once onAdData has been triggered (see Listen to ad data).

public class PlaybackActivity extends Activity {

// Your player object
private Object mPlayer;

// SmartLib StreamingSession
private StreamingSession mSession;

// It is recommended to use a different thread to start a session
private ExecutorService mExecutor = Executors.newSingleThreadExecutor();


protected void onCreate(Bundle savedInstanceState) {

// Create the player
mPlayer = PlayerFactory.newInstance();

// Registering to player error events

// Create a StreamingSession object
mSession = SmartLib.getInstance().createStreamingSession();

// Attach the player to the session

// Listen to ad data, triggered during SmartLib getURL
mSession.setAdDataListener(adList -> {
// Get the position from your custom app storage
long bookmarkPosition = mAppStorage.getPosition(mContentId);

// Generate the playback position with SmartLib
long playbackPosition = mSession.getPositionForPlayback(bookmarkPosition);;;

// Activate the advertising workflow

// Start the session in a different thread, getURL can make requests to the Broadpeak CDN, nanoCDN...
mExecutor.submit(() -> {
StreamingSessionResult result = mSession.getURL(...);

if (!result.isError()) {
// Load URL without playing
} else {


public void onPlayerError(PlaybackException error) {
// If the playback has been canceled because of a player error
// (i.e. non-recoverable error), stop the streaming session
if (error.playbackCanceled) {