Ad Breaks

The Android TV Receiver SDK features native support for ad breaks and companion ads within a given media stream.

See the Web Receiver Ad Breaks Overview for more information on how Ad Breaks work.

Load with ad breaks on sender

On the senders, you can specify ad breaks in a load command using AdBreakClipInfo and AdBreakInfo:


AdBreakClipInfo breakClip1 =
    new AdBreakClipInfo.Builder("bc1")
        .setTitle("Clip title")
        .setWhenSkippableInMs(5000)  // Set this field so that the ad is skippable

AdBreakClipInfo breakClip2 = …
AdBreakClipInfo breakClip3 = …

AdBreakInfo break1 =
    new AdBreakInfo.Builder(/* playbackPositionInMs= */ 10000)

MediaInfo mediaInfo = new MediaInfo.Builder()
    .setAdBreakClips({breakClip1, breakClip2, breakClip3}).build();

MediaLoadRequestData mediaLoadRequestData = new MediaInfo.Builder()


Handling load with ad breaks on Android TV

On your Android TV app, the breaks will be included in MediaLoadRequestData. Load requests can be processed normally and the AdBreakClips and AdBreaks can be retrieved from the MediaInfo:

public class MyMediaLoadCommandCallback extends MediaLoadCommandCallback {
  public Task<MediaLoadRequestData> onLoad(String senderId, MediaLoadRequestData loadRequestData) {
    return -> {
        // Resolve the entity into your data structure and load media.
        MediaInfo mediaInfo = loadRequestData.getMediaInfo();


        myPrepareAdBreaks(mediaInfo.getAdBreakClips(), mediaInfo.getAdBreaks());

        // Update media metadata and state (this clears all previous status
        // overrides).
            .setDataFromLoad(mediaInfo); // Ad breaks are set on the modifier.


        // Return the resolved MediaLoadRequestData to indicate load success.
        return loadRequestData;

Updating ad breaks on Android TV

When ads start playing you need to update the AdBreakStatus on the MediaStatusModifier to broadcast that your app has started playing ads:

AdBreakStatus breakStatus =
    new AdBreakStatus.Builder()
        .setWhenSkippableInMs(5000)  // Set this field so that the ad break clip is skippable


You can also dynamically modify the ad breaks after an item is loaded:

AdBreakClipInfo breakClip1 = ...
AdBreakClipInfo breakClip2 = ...
AdBreakClipInfo breakClip3 = ...

AdBreakInfo break1 = ...
AdBreakInfo break2 = ...

    .setAdBreakClips({breakClip1, breakClip2, breakClip3})
    .setAdBreaks({break1, break2});

Enable and handle ad skipping

When an ad break is playing, the senders will show a button to skip the current ad break clip if it is skippable. To enable the ability for a user to skip an ad break clip, use the MediaStatusModifier to add the COMMAND_SKIP_AD media command:

mMediaManager.getMediaStatusModifier().setMediaCommandSupported(MediaStatus.COMMAND_SKIP_AD, true);

To handle the SKIP_AD command, implement the onSkipAd callback in your CastActionCallbacks:

public MyMediaCommandCallback extends MediaCommandCallback {
  public Task<Void> onSkipAd(RequestData requestData) {
    // Skip your ad
    return Tasks.forResult(null);

MediaManager mediaManager =
mediaManager.setMediaCommandCallback(new MyMediaCommandCallback());

Client-side stitching

Client-side stitching is where ads are not embedded in the stream. For Cast Connect, in addition to updating the AdBreakStatus on the MediaStatusModifier you will need to set the playback speed to 0 on the PlaybackStateCompat so the senders know to freeze the content timeline progress.

// Playback speed should be 0 if content is not playing.
if (adIsPlaying) {
    playbackSpeed = 0.0f;
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
stateBuilder.setState(playbackStateCompat, position, playbackSpeed);

Once the ad finishes, you should resume the previous playback speed.

Server-side stitching

For server-side stitching, the ads are embedded so the server is expected to provide a single stream that contains both the content and ads. In this case, playback can continue progressing normally as the timeline contains the duration of the ad in addition to the content.