Free Preview
Free Preview authorizes a limited playback allowance. Android apps opt in on the content authorization request, then pass the returned allowance to HeartbeatManager for tracking.
Modes
| Mode | Applicable content | Consumption tracking |
|---|---|---|
FULL | Live and VOD | Server-backed. Heartbeats report consumed preview time; the server decides extensions. |
LIGHT | Supported for LIVE only | Consumption is persisted locally. The app decides whether to grant more time, for example after calling its backend. |
Request authorization
Set freePreview and fpMode on the PlatformAsset sent to authorizePlayback. FULL supports Live and VOD; LIGHT is supported for LIVE only.
val previewAsset = PlatformAsset(
mediaID = contentID,
mediaType = MediaType.DASH,
consumptionType = ConsumptionType.LIVE, // Use VOD for on-demand content.
catalogType = catalogType,
freePreview = true,
fpMode = FreePreviewMode.FULL
)
val result = contentAuthorizer.authorizePlayback(previewAsset, null)
When authorization succeeds, ContentAuthorizationToken.freePreview contains the allowance, or null when no preview was authorized.
| Property | Meaning |
|---|---|
fpMode | FULL or LIGHT |
totalDuration | Total allowance, in seconds |
consumedDuration | Previously consumed time, in seconds |
remainingDuration | Available time, in seconds |
groupId | Optional identifier for sharing an allowance across related content |
{
"freePreview": {
"fpMode": "full",
"totalDuration": 300.0,
"consumedDuration": 0.0,
"remainingDuration": 300.0,
"groupId": "optional-group"
}
}
Configure heartbeat tracking
Pass the authorization response, main content's playback type, and Android Context to HeartbeatFactory.createHeartbeatManager.
val heartbeatManager = HeartbeatFactory.createHeartbeatManager(
contentId = token.contentID,
deviceId = deviceId,
heartbeatToken = token.heartbeatToken,
heartbeatConfiguration = heartbeatConfiguration,
platformAuthorizer = platformAuthorizer,
player = player,
freePreview = token.freePreview,
contentPlaybackType = when (previewAsset.consumptionType) {
ConsumptionType.LIVE -> ContentPlaybackType.LIVE
ConsumptionType.VOD -> ContentPlaybackType.VOD
},
context = context.applicationContext
)
For consumption tracking, pass all three values: freePreview, contentPlaybackType, and context. contentPlaybackType must describe the main asset, not an ad or slate. Omitting either contentPlaybackType or a usable context prevents reliable Light-mode consumption tracking and persistence.
Preview configuration
Set these properties on HeartbeatConfiguration. The existing heartbeat interval remains independent of preview-extension checks.
| Property | Default | Behavior |
|---|---|---|
freePreviewExtensionCheckSec | 60.0 seconds | Remaining time that triggers an extension check. |
jitterSec | 60.0 seconds | Maximum random extra time for the initial Light allowance, in 10-second increments. 0.0 disables jitter. |
onFreePreviewExtension | null | Light-mode callback. The app may call its backend, then return additional seconds or 0.0 to decline. If unset, Light extensions are declined. Full mode checks with the server. |
onFreePreviewProgress | null | Callback for the initial allowance and each change in displayed whole seconds remaining. |
val heartbeatConfiguration = HeartbeatConfiguration(
heartbeatEndPointURL = heartbeatEndPointURL,
freePreviewExtensionCheckSec = 60.0,
jitterSec = 60.0,
onFreePreviewExtension = { preview ->
// Light only: return extra seconds, or 0.0 to decline.
0.0
},
onFreePreviewProgress = { preview ->
// Update the UI with preview.remainingDuration.
}
)
Handle timeline events
Listen through Player.Listener.onEventReceived and take the app-appropriate action:
val listener = object : Player.Listener {
override fun onEventReceived(
streamTimelineEvent: StreamTimelineEvent,
suggestedAction: Action,
streamTimelineMetadata: StreamTimelineMetadata?
) {
when (streamTimelineEvent) {
StreamTimelineEvent.FREE_PREVIEW_WILL_END -> {
val preview = (streamTimelineMetadata as? FreePreviewWillEndMetadata)?.preview
// Show a warning using preview?.remainingDuration.
}
StreamTimelineEvent.FREE_PREVIEW_ENDED -> {
val reason = (streamTimelineMetadata as? FreePreviewEndedMetadata)?.reason
// Show sign-in/subscription UI; the SDK stops playback.
}
else -> Unit
}
}
}
player.addListener(listener)
Flow summary
- Request authorization with
freePreview = trueand the selectedfpMode. - Pass
token.freePreview, the main content'scontentPlaybackType, and a stablecontexttoHeartbeatManager. - Configure callbacks in
HeartbeatConfigurationand handle timeline events inPlayer.Listener. - Listen to timeline events and take the app-appropriate UI action, such as warning the user or showing subscription UI.
Heartbeat behavior and event timing
The configured heartbeat interval (default 60,000 ms) controls regular heartbeat requests.
- Full: Heartbeats include
fpMode=fullandfpConsumedDuration; at the extension threshold, the SDK calls the server. - Light: Heartbeats include
fpMode=light; consumed time stays local, and the SDK invokesonFreePreviewExtensionat the threshold. FREE_PREVIEW_WILL_END: Warns that preview playback is going to end.FREE_PREVIEW_ENDED: ReportsALLOWANCE_EXHAUSTED,UNSUPPORTED_CONTENT, orSERVER_STOP.