Skip to main content

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.

note

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.

ModeApplicable contentConsumption tracking
.fullLive and VODServer-backed. Heartbeats report consumed time, and the server handles extensions and persistence.
.lightLive 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).

PropertyDescription
fpMode.full or .light.
totalDurationTotal allowance, in seconds (TimeInterval).
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 in FLHeartbeatFactory.heartbeatConfiguration(...), pass contentPlaybackType and freePreview to FLHeartbeatFactory.heartbeatManager(...), and attach Heartbeat to composablePlayer 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.
onFreePreviewExtensionnilLight-mode async callback (((FreePreview) async -> TimeInterval)?). Return additional seconds to extend, or 0 to decline. Full mode checks with the server.
onFreePreviewProgressnilOptional 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 is FreePreviewWillEndMetadata.
  • StreamTimelineEvent.freePreviewEnded: Emitted when the preview ends, followed by player.stop() on the main thread. Metadata is FreePreviewEndedMetadata 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 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.