Free Preview
Free Preview lets viewers sample live and on-demand content on iOS and tvOS
before signing in or subscribing. Opt in on the content authorization request,
pass the returned allowance to HeartbeatManager, 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.
This guide describes the free-preview API targeting iOS SDK 7.0.341 (pending
release). Verify that your installed FLPlayerInterface,
FLContentAuthorizer, and FLHeartbeat modules include these APIs before
using them.
Preview modes
Choose a preview mode when requesting playback authorization.
| Mode | Applicable content | Consumption tracking |
|---|---|---|
.full | Live and VOD | Server-backed. Heartbeats report consumed time, and the server handles extensions and persistence. |
.light | Live only (GDFO) | Stored locally in UserDefaults. Your app decides extensions through onFreePreviewExtension. |
Request authorization
Set freePreview: true and fpMode on the PlatformAsset constructed with
FLContentAuthorizerFactory.platformAsset(...).
import FLContentAuthorizer
import FLPlayerInterface
let request = FLContentAuthorizerFactory.platformAsset(
contentId: contentId,
contentType: .live, // Use .vod for full-mode VOD
catalogType: catalogType,
mediaFormat: .hls,
drm: .fairplay,
freePreview: true,
fpMode: .light // .full or .light
)
contentAuthorizer.authorizeContent(asset: request, delivery: .streaming) { result in
switch result {
case let .success(playbackAsset):
// Use playbackAsset.contentUrl with your normal player setup flow.
// playbackAsset.freePreview, playbackAsset.heartbeatToken, and
// playbackAsset.heartbeatFrequency are optional.
break
case let .failure(error):
// Handle authorization failure.
break
}
}
When authorization succeeds, playbackAsset.freePreview contains the
FreePreview allowance (or nil if no preview was authorized).
| Property | Description |
|---|---|
fpMode | .full or .light. |
totalDuration | Total allowance, in seconds (TimeInterval). |
consumedDuration | Previously consumed time, in seconds. |
remainingDuration | Available time, in seconds. |
groupId | Optional 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 in FLHeartbeatFactory.heartbeatConfiguration(...), pass
contentPlaybackType and freePreview to
FLHeartbeatFactory.heartbeatManager(...), and attach Heartbeat to
composablePlayer before playback starts.
| Property | Default | Behavior |
|---|---|---|
freePreviewExtensionCheckSec | 60 s | Remaining time that triggers an extension check. |
jitterSec | 60 s | Maximum random extra time for the initial Light allowance, in 10-second buckets. 0 disables jitter. |
onFreePreviewExtension | nil | Light-mode async callback (((FreePreview) async -> TimeInterval)?). Return additional seconds to extend, or 0 to decline. Full mode checks with the server. |
onFreePreviewProgress | nil | Optional callback (((FreePreview) -> Void)?) for the initial allowance and each change in displayed whole seconds remaining. |
import FLHeartbeat
import FLPlayerInterface
let config = FLHeartbeatFactory.heartbeatConfiguration(
heartbeatEndPointUrl: heartbeatEndpoint,
syncInterval: playbackAsset.heartbeatFrequency ?? 60000, // Milliseconds; defaults to 60000
freePreviewExtensionCheckSec: 60,
jitterSec: 60,
onFreePreviewExtension: { preview in
// Light mode only: return extra seconds to grant, or 0 to decline.
await getLightPreviewExtensionSeconds(preview)
},
onFreePreviewProgress: { preview in
showPreviewRemaining(preview.remainingDuration)
}
)
let heartbeat = FLHeartbeatFactory.heartbeatManager(
configuration: config,
deviceId: deviceId,
contentId: playbackAsset.contentId,
catalogType: catalogType,
heartbeatToken: playbackAsset.heartbeatToken ?? "",
authorizer: platformAuthorizer,
contentPlaybackType: .live, // Main content type (.live or .vod), even with pre-roll ads
freePreview: playbackAsset.freePreview // Pass nil to leave preview tracking disabled
)
composablePlayer.addStateChangeBlock(heartbeat.processPlaybackStateChange)
composablePlayer.addHeartBeatBlock(heartbeat.processPlaybackProgress)
For Light mode, contentPlaybackType 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
Implement PlayerDelegate.didReceive(event:suggestedAction:metadata:) before
loading or starting the player.
import FLPlayerInterface
func didReceive(
event: StreamTimelineEvent,
suggestedAction: Action,
metadata: StreamTimelineMetadata?
) {
switch event {
case .freePreviewWillEnd:
if let meta = metadata as? FreePreviewWillEndMetadata {
showPreviewCountdownBanner(Int(meta.preview.remainingDuration.rounded()))
}
case .freePreviewEnded:
let meta = metadata as? FreePreviewEndedMetadata
// The SDK stops playback; display your sign-in or subscription UI.
showSubscriptionPrompt(reason: meta?.reason, preview: meta?.preview)
default:
break
}
}
Both events use Action.none:
StreamTimelineEvent.freePreviewWillEnd: Emitted when an extension check is declined with time remaining. Metadata isFreePreviewWillEndMetadata.StreamTimelineEvent.freePreviewEnded: Emitted when the preview ends, followed byplayer.stop()on the main thread. Metadata isFreePreviewEndedMetadatawithreasonset to.allowanceExhaustedor.serverStop(fromGRACEFUL_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 FLHeartbeat
do {
let result = try FreePreviewStore.getConsumption(
FreePreviewStoreKey(
contentId: contentId, // Required, even when groupId is supplied
groupId: groupId, // Optional; use the same group ID as playback
totalDuration: currentAllowanceSeconds // Optional; include any app grants
)
)
switch result {
case let .found(consumedDuration, totalDuration, isExhausted):
if isExhausted == true {
// Show preview-exhausted UI.
} else if isExhausted == false {
// Local allowance remains.
}
case .notFound:
// No local record exists.
break
case let .unavailable(reason):
// reason is .storage or .invalidRecord.
break
}
} catch let error as FreePreviewStoreError {
// .emptyContentId, .emptyGroupId, or .invalidTotalDuration
}
For .found results, isExhausted is non-nil only when a stored or supplied
total is available. Records are local to the device and app container, not
account-wide.
To clear all SDK Light-mode records without affecting unrelated UserDefaults
entries:
do {
try FreePreviewStore.clearAll()
} catch {
// Handle storage error.
}
Next steps
Explore related playback and authorization guides:
- Secure Playback: Authorize playback assets and start streams.
- Heartbeat: Configure heartbeat session monitoring, concurrency limits, and live event handling.