Select platform: [HTML5](https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/html5/snapback "View this page for the HTML5 platform docs.") [Android](https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/android/snapback "View this page for the Android platform docs.") [iOS](https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/ios/snapback "View this page for the iOS platform docs.") [tvOS](https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/tvos/snapback "View this page for the tvOS platform docs.") [Roku](https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/roku/snapback "View this page for the Roku platform docs.")

<br />

As a video publisher, you may want to prevent your viewers from
seeking past your mid-roll ads. When a user seeks past an ad break,
you can take them back to the start of that ad break, and then return
them to their seek location after that ad break has completed. This
feature is called "snapback."

As an example, see the diagram below. Your viewer is watching a video,
and decides to seek from the 5-minute mark to the 15-minute mark.
There is, however, an ad break at the 10-minute mark that you want
them to watch before they can watch the content after it:

![](https://developers.google.com/static/interactive-media-ads/images/dai_snapback1.png)

In order to show this ad break, take the following steps:

1. Check if the user ran a seek that jumped past an unwatched ad break, and if so, take them back to the ad break.
2. After the ad break completes, return them to their original seek.

In diagram form, that looks like this:

![](https://developers.google.com/static/interactive-media-ads/images/dai_snapback2.png)

Here's how to implement this workflow in the IMA DAI SDK, as done in
[AdvancedExample](https://github.com/googleads/googleads-ima-android-dai).

## Prevent a seek from leaving an ad break unwatched

Check if the user has run a seek that went past an unwatched ad break,
and if so, take them back to the ad break.
In the Android SDK, use the `PlayerControl` object to detect seeking.
When the user seeks, trigger the `onSeek()` method of the
`SampleHlsVideoPlayerCallback` implemented by `SampleAdsWrapper`.
That method (presented below) checks the cue point prior to the user's
seek time. If it is unplayed, seek to the beginning of that ad break
instead of their initial desired seek point, and save that desired seek
point in `snapBackTime`.

    @Override
    public void onSeek(int timeMillis) {
      double timeToSeek = timeMillis;
      if (streamManager != null) {
        CuePoint cuePoint =
            streamManager.getPreviousCuePointForStreamTime(timeMillis / 1000);
        if (cuePoint != null && !cuePoint.isPlayed()) {
          snapBackTime = timeToSeek / 1000.0; // Update snapback time.
          // Missed cue point, so snap back to the beginning of cue point.
          timeToSeek = cuePoint.getStartTime() * 1000;
          videoPlayer.seek(Math.round(timeToSeek));
          videoPlayer.setCanSeek(false);
          return;
        }
      }
      videoPlayer.seek(Math.round(timeToSeek));
    }

## Put the user back to their original seek

Now when you get an `onAdBreakEnded` event, check to see if `snapBackTime`
is set. If so, take the user to that point in the stream, because the ad
break they just watched was the result of snapback:

    @Override
    public void onAdBreakEnded() {
      // Re-enable player controls.
      videoPlayer.setCanSeek(true);
      videoPlayer.enableControls(true);
      if (snapBackTime > 0) {
        videoPlayer.seek(Math.round(snapBackTime * 1000));
      }
      snapBackTime = 0;
    }