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:
In order to show this ad break, take the following steps:
- Check if the user ran a seek that jumped past an unwatched ad break, and if so, take them back to the ad break.
- After the ad break completes, return them to their original seek.
In diagram form, that looks like this:
Here's how to implement this workflow in the Roku IMA SDK, as done in our Advanced Example.
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. The Roku advanced sample relies on remote button presses for the user to seek - each time the user presses the forward button, they jump forward in the stream by a set number of seconds. The same method that handles this jump also checks to see if the jump takes/ them past or into an ad break, and if it does, sends the user to the start of that ad break instead:
Function handleFastForward(player as Object, streamManager as Object, updatedTime As Integer) previousAd = streamManager.getPreviousCuePoint(updatedTime) If previousAd = Invalid or previousAd.hasPlayed player.seek(updatedTime * 1000) Else If previousAd.start > player.currentTime player.isSnapback = True player.timeAfterSnapback = updatedTime player.seek(previousAd.start * 1000 + 1000) End If End Function
Put the user back to their original seek
adBreakEnded handler, check to see if the previous ad
break was played as the result of snapback. If so, return the
user to the place they were trying to seek to initially (as long
as it wasn't the middle of the ad break that just played):
player.adBreakEnded = Function(adBreakInfo as Object) If m.isSnapback m.seek(m.timeAfterSnapback * 1000) m.isSnapback = False End If End Function