Skip to main content

Free Preview

Free Preview lets viewers sample live and on-demand content before signing in or subscribing. Opt in on the content authorization request, pass the returned allowance to Heartbeat, and respond to timeline events in your app.

Paused, buffering, seeking, and ad playback don't consume preview time. When the allowance ends, the SDK stops playback; your app displays the sign-in, registration, or subscription UI.

note

This guide describes the free-preview API targeting Web SDK 7.1.292 (pending release). Verify that your installed @quickplay/heartbeat, @quickplay/content-authorization, and @quickplay/player-interface packages include these APIs before using them.

Preview modes​

Choose a preview mode when requesting playback authorization.

ModeApplicable contentConsumption tracking
fullLive and VODServer-backed. Heartbeats report consumed time, and the server handles extensions and persistence.
lightLive only (GDFO)Stored locally in localStorage. Your app decides extensions through onFreePreviewExtension.

Request authorization​

Set freePreview: true and fpMode on the PlatformAsset passed to contentAuthorizer.authorizePlayback.

import {
ConsumptionType,
type PlatformAsset,
} from '@quickplay/content-authorization';

const request: PlatformAsset = {
...existingPlatformAsset, // Includes mediaID, catalogType, mediaType, and drmScheme
consumptionType: ConsumptionType.LIVE, // Use ConsumptionType.VOD for full-mode VOD
freePreview: true,
fpMode: 'light', // 'full' or 'light'
};

const asset = await contentAuthorizer.authorizePlayback(request);
// Use asset.contentUrl with your normal player setup flow.
// asset.freePreview, asset.bandwidth, asset.heartbeatToken, and asset.heartbeatFreq are optional.

When authorization succeeds, asset.freePreview contains the allowance (or undefined if no preview was authorized).

PropertyDescription
fpMode'full' or 'light'.
totalDurationTotal allowance, in seconds.
consumedDurationPreviously consumed time, in seconds.
remainingDurationAvailable time, in seconds.
groupIdOptional identifier for sharing a Light-mode allowance across related content (defaults to contentId).
{
"freePreview": {
"fpMode": "light",
"totalDuration": 300,
"consumedDuration": 0,
"remainingDuration": 300,
"groupId": "preview-group"
}
}

Configure heartbeat tracking​

Set preview options on HeartbeatConfiguration, pass asset.freePreview and the main content's playback type to HeartbeatBuilder, and attach Heartbeat to the player before playback starts.

PropertyDefaultBehavior
freePreviewExtensionCheckSec60 sRemaining time that triggers an extension check.
jitterSec60 sMaximum random extra time for the initial Light allowance, in 10-second buckets. 0 disables jitter.
onFreePreviewExtension—Light-mode async callback. Return additional seconds to extend, or 0 to decline. Full mode checks with the server.
onFreePreviewProgress—Optional callback for the initial allowance and each change in displayed whole seconds remaining.
import {
createHeartbeatBuilder,
type HeartbeatConfiguration,
} from '@quickplay/heartbeat';
import { createComposablePlayer } from '@quickplay/platform-player';

const config: HeartbeatConfiguration = {
heartbeatEndPointUrl: 'https://heartbeat.example.com',
syncIntervalMS: asset.heartbeatFreq, // Milliseconds; defaults to 60000
freePreviewExtensionCheckSec: 60,
jitterSec: 60,
onFreePreviewExtension: async (preview) => {
// Light mode only: return extra seconds to grant, or 0 to decline.
return checkUserPreviewExtension(preview.groupId);
},
onFreePreviewProgress: (preview) => {
updatePreviewCountdown(preview.remainingDuration);
},
};

const heartbeat = createHeartbeatBuilder(
deviceId,
asset.contentId,
config,
platformAuthorizer,
)
.setHeartbeatToken(asset.heartbeatToken)
.setContentPlaybackType(request.consumptionType) // Main content type, even with pre-roll ads
.setCatalogType(request.catalogType)
.setFreePreview(asset.freePreview) // Pass undefined to leave preview tracking disabled
.build();

const composable = createComposablePlayer(player);
composable.addStateChangeStep(heartbeat.processPlayerStateChange);
composable.addHeartBeatStep(heartbeat.processHeartbeatChange);

For Light mode, setContentPlaybackType must be 'live', even when playback begins with a pre-roll ad. For non-live content, the SDK skips Light-preview tracking while normal heartbeat handling continues.

Handle timeline events​

Subscribe to streamtimelineevent before loading or starting the player, and unsubscribe when disposing of or replacing the player.

import {
StreamTimelineEvent,
type Action,
type FreePreviewEndedMetadata,
type FreePreviewWillEndMetadata,
} from '@quickplay/player-interface';

const onTimelineEvent = (
event: StreamTimelineEvent,
_action: Action,
metadata?: FreePreviewWillEndMetadata | FreePreviewEndedMetadata,
) => {
if (event === StreamTimelineEvent.FREE_PREVIEW_WILL_END) {
const { preview } = metadata as FreePreviewWillEndMetadata;
showPreviewCountdownToast(Math.round(preview.remainingDuration));
}

if (event === StreamTimelineEvent.FREE_PREVIEW_ENDED) {
const { reason } = metadata as FreePreviewEndedMetadata;
// The SDK stops playback; display your sign-in or subscription UI.
showSubscriptionPaywall(reason);
}
};

player.subscribe('streamtimelineevent', onTimelineEvent);
player.load();

Both events use Action.NONE:

  • StreamTimelineEvent.FREE_PREVIEW_WILL_END: Emitted when an extension check is declined with time remaining. Metadata provides { preview }.
  • StreamTimelineEvent.FREE_PREVIEW_ENDED: Emitted when the preview ends, followed by player.stop() (regardless of stopPlayerOnStreamTimelineEvent). Metadata provides { reason, preview? } with reason set to 'allowanceExhausted' or 'serverStop' (from GRACEFUL_STOP).

Check local Light-mode consumption​

Use FreePreviewStore to read locally persisted Light-mode usage before creating a player, or to reset local records when your app policy requires it.

import { FreePreviewStore } from '@quickplay/heartbeat';

const result = FreePreviewStore.getConsumption({
contentId, // Required, even when groupId is supplied
groupId, // Optional; use the same group ID as playback
totalDuration: currentAllowanceSeconds, // Optional; include any app grants
});

switch (result.status) {
case 'found':
if (result.isExhausted === true) {
// Show preview-exhausted UI.
} else if (result.isExhausted === false) {
// Local allowance remains.
}
break;
case 'not-found':
// No local record exists.
break;
case 'unavailable':
// result.reason is 'storage' or 'invalid-record'.
break;
}

For 'found' results, isExhausted is set only when a stored or supplied total is available. Empty contentId or groupId values throw TypeError, and an invalid totalDuration throws RangeError. Records are local to the device and origin, not account-wide.

To clear all SDK Light-mode records for the current origin without affecting unrelated localStorage entries:

try {
FreePreviewStore.clearAll();
} catch (error) {
console.error('Unable to clear local free-preview records', error);
}

Next steps​

Explore related playback and authorization guides:

  • Basic Playback: Set up player instances and load authorized streams.
  • Platform Heartbeat: Configure heartbeat session monitoring, concurrency limits, and live event handling.