Skip to main content

Configuration

Before starting​

  • DivaConfiguration (iOS) and DivaTVConfiguration (tvOS) hold the parameters you pass to DIVA Player when you create it: Diva(configuration:) on iOS, DivaTV(configuration:) on tvOS.
  • DIVA Player reads the configuration once, when it's created. Set every property before creating the player: later changes have no effect.
  • Refer to the Basic instantiation code article to see where the configuration fits in your code.
  • Refer to the Video player instantiation input article to understand the role of settings, dictionary, videoId and VideoMetadata.

This reference describes DIVA Player iOS/tvOS 5.12.6.

iOS: DivaConfiguration​

Mandatory properties​

PropertyTypeDescription
settingsSWSettingCleanModelDIVA settings: they set up, enable or disable, and adapt DIVA Player features and UX to your project. See Settings.
dictionarySWDictionaryCleanModelLocalized strings used in the DIVA Player UI, as key/value pairs. See Dictionary.
videoIdStringID of the video to open. DIVA Player passes it to videoMetadataProvider to get the video's metadata.
videoMetadataProviderVideoMetadataProviderObject DIVA Player calls to get the VideoMetadata of a video. See VideoMetadataProvider.

Optional properties​

PropertyTypeDefaultDescription
entitlementProviderEntitlementProvider?nilEntitlement check and content protection: checks whether the user can play a video, returns the data needed to play it (for example DRM data or an adjusted stream URL) and lets DIVA Player show a message when the video can't be played. Leave it nil if you don't need entitlement checks.
customFairplayResourceLoaderCommonFairplayResourceLoader?nilFairPlay DRM support. Leave it nil if your streams aren't DRM-protected.
settingsErrorString""Message shown when the settings can't be used.
networkErrorString""Message shown when there's a network error.
params[String: String][:]Extra parameters for DIVA Player's string resolver. Each key is added with the settings. prefix: for example, the key token is available as settings.token.
deepLinkTypeDiva.DeeplinkType.relativeHow DIVA Player reads deepLinkValue:
• .relative: an offset from the start of the video.
• .absolute: a date and time, synchronized with the video's timecodeIn.
deepLinkValueString""Position where the video starts.
• With .relative: an integer number of milliseconds, for example "600000" starts at 10 minutes.
• With .absolute: an ISO 8601 date and time, format yyyy-MM-ddThh:mm:ss.
Leave it empty to start at the default position.
defaultAudioTrackString?nilAudio track selected when the video starts. Use the format set by audioSelectionMethod in the general settings.
defaultCCTrackString?nilClosed caption track selected when the video starts. Use the format set by closedCaptionSelectionMethod in the general settings.
maxBitratePreferencesDouble-1Maximum bitrate, in kbps. -1 (or any value ≤ 0) means no limit. Not applied to 360° videos, nor when video quality selection is enabled.
hdrModeBoolfalseEnables the HDR menu, which lets users switch between HDR and SDR. DIVA Player requests the VideoMetadata of the selected version from videoMetadataProvider, with the expected type in playbackState.hdrType.
highlightsModeSettings.HighlightsFilters.FilterType?nilStarts the player in highlights mode with the given filter: .short, .medium, .long or .live. nil starts normal playback.
logLevelDivaLogLevel.debugMinimum level of the DIVA Player logs: .debug, .info, .notice, .error or .fault.
embedModeDiva.EmbedMode.fullscreenHow the player is shown:
• .fullscreen: the player takes the whole screen, with all its controls.
• .chromeless(loopback:): the player is embedded in your view hierarchy, with no UI controls. With loopback: true the video plays again when it ends; with false it pauses at the end.
.embedded is deprecated.
daiImaAdTagParameters[String: String][:]Overrides a limited set of Google IMA DAI ad tag parameters on the stream request. See the Google IMA DAI documentation.
timelineIconThresholdUInt22Distance, in points, under which colliding timeline icons are grouped. 0 disables grouping.
sessionIdStringUUID().uuidStringID of this DIVA Player instance's lifecycle. A new ID is created for every instance and discarded when the player is removed from memory.
liveToVodTransitionModeLiveToVodTransitionMode.endOfPlayWhat the viewer sees when the live event being watched is finalized into a VOD: .endOfPlay, .restartFromZero or .customNotifier. Available from 5.12.6. See Configure the live-to-VOD transition.

Callbacks​

All callbacks are optional and default to nil.

PropertyTypeDescription
onVideoError(VideoError, VideoMetadata?) -> VoidCalled when a video error happens, with the error and the metadata of the video, if available. See Errors.
onAnalyticEvent(AnalyticsEvent) async -> VoidCalled for every analytics event. See Analytics for the list of events.
onMediaAnalyticsUpdate(MediaAnalyticsUpdate) async -> VoidExposes low-level media player events, to integrate media analytics providers such as Conviva or YOUBORA. See Media analytics and How media analytics updates are delivered.
onCustomActionResponse((actionId: String, videoMetadata: VideoMetadata)) -> VoidCalled when the user triggers a custom action, with the action ID and the metadata of the current video.
onExit(Bool) async -> VoidCalled when the player is about to close. The value is true when the user closed the player.
onPreferredAudioTrack(String) -> VoidCalled when the user selects an audio track, with the track ID.
onPreferredCCTrack(String) -> VoidCalled when the user selects a closed caption track, with the track ID.
onVideoEnd(String) async -> VoidCalled when a video ends, with its video ID.
onPlaybackSession@Sendable (String) async -> VoidCalled when the playback session changes, with the playback session ID.
onMediaListItemClick(SWMediaListItemCleanModel) async -> VoidCalled when the user selects an item in a media list.
visibilityUpdates(Bool) -> VoidCalled with true when the player view disappears and false when it appears again. Not in the initializer: set the property.

Full configuration example​

var config = DivaConfiguration(
// Mandatory
settings: settings,
dictionary: dictionary,
videoId: videoId,
videoMetadataProvider: ExampleVideoMetadataProvider(),
// Optional
entitlementProvider: entitlementProvider,
customFairplayResourceLoader: fairplayResourceLoader,
settingsError: "Settings Error",
networkError: "Network Error",
params: ["token": userToken],
deepLinkType: .relative,
deepLinkValue: "600000",
defaultAudioTrack: "English",
defaultCCTrack: "English",
maxBitratePreferences: 6000,
hdrMode: false,
highlightsMode: nil,
logLevel: .notice,
embedMode: .fullscreen,
daiImaAdTagParameters: ["npa": "1"],
timelineIconThreshold: DivaConfiguration.Constants.defaultTimelineIconThreshold,
liveToVodTransitionMode: .endOfPlay
)

config.onVideoError = { error, videoMetadata in
print("[VideoError] \(error.type.rawValue) \(error.message) videoId: \(videoMetadata?.videoId ?? "unknown")")
}
config.onAnalyticEvent = { event in
print("[EVENT] \(event.type)")
}
config.onMediaAnalyticsUpdate = { update in
await ConvivaAnalytics.shared.handle(update)
}
config.onExit = { [weak self] isFromUser in
self?.dismiss(animated: true)
}
config.onVideoEnd = { videoId in
print("[VideoEnd] \(videoId)")
}
config.visibilityUpdates = { isHidden in
print("[Visibility] hidden: \(isHidden)")
}

Task { @MainActor [weak self] in
guard let self else { return }
self.diva = await Diva(configuration: config)
self.diva?.setTargetView(view: self.view, viewController: self)
}

Downloads and offline playback​

DivaConfiguration has two factory methods for downloaded videos:

  • DivaConfiguration.forDownloads(settings:dictionary:videoId:videoMetadataProvider:entitlementProvider:customFairplayResourceLoader:fairPlayCertificateUrl:sessionId:logLevel:embedMode:params:) creates the configuration used to download a video. If you pass fairPlayCertificateUrl, it's added to params as FairPlayCertificateURL. params defaults to ["Offline": "true"].
  • DivaConfiguration.forOffline(videoId:localURL:fairplayResourceLoader:sessionId:logLevel:embedMode:params:onExit:onPlaybackSession:onVideoError:) creates the configuration to play a downloaded video from localURL. It reads the settings, dictionary and VideoMetadata saved with the download, and falls back to basic settings when they aren't available. Get localURL from DownloadManager.shared.getDownloadURL(itemKey:).

tvOS: DivaTVConfiguration​

Mandatory properties​

The initializer takes dictionary before settings.

PropertyTypeDescription
dictionarySWDictionaryCleanModelLocalized strings used in the DIVA Player UI, as key/value pairs. See Dictionary.
settingsSWSettingCleanModelDIVA settings: they set up, enable or disable, and adapt DIVA Player features and UX to your project. See Settings.
videoIdStringID of the video to open. DIVA Player passes it to videoMetadataProvider to get the video's metadata.
videoMetadataProviderVideoMetadataProviderObject DIVA Player calls to get the VideoMetadata of a video. See VideoMetadataProvider.

Optional properties​

PropertyTypeDefaultDescription
videoPlaceholderThumbnailUIImage?nilPlaceholder image shown before the video starts.
customFairplayResourceLoaderCommonFairplayResourceLoader?nilFairPlay DRM support: pass a class that conforms to FairplayResourceLoader. Leave it nil if your streams aren't DRM-protected.
defaultAudioTrackString?nilAudio track selected when the video starts. Use the format set by audioSelectionMethod in the general settings.
defaultCCTrackString?nilClosed caption track selected when the video starts. Use the format set by closedCaptionSelectionMethod in the general settings.
deepLinkTypeDivaTV.DeeplinkType.relativeHow DIVA Player reads deepLinkValue: .relative (offset from the start) or .absolute (date and time).
deepLinkValueString""Position where the video starts.
• With .relative: milliseconds from the start, for example "600000" starts at 10 minutes.
• With .absolute: an ISO 8601 date and time, format yyyy-MM-ddThh:mm:ss.
entitlementProviderEntitlementProvider?nilEntitlement check and content protection: checks whether the user can play a video and lets DIVA Player show a message when it can't. Leave it nil if you don't need entitlement checks.
embedModeDivaModel.EmbedMode.fullscreenHow the player is shown:
• .fullscreen: the full player, with menus and overlays. Present playerViewController modally or as a child view controller.
• .chromeless(loopback:): only the video, with no UI. Add playerViewController.view to your own container. With loopback: true the video plays again when it ends; with false it pauses at the end.
hdrModeBoolfalseEnables the HDR menu in the transport bar, which lets users switch between HDR and SDR. DIVA Player requests the VideoMetadata of the selected version from videoMetadataProvider, with the expected type in playbackState.hdrType.
imaClientSideProviderImaClientSideProviderType?nilGoogle IMA client-side ads provider, available in the DivaImaAdvertisement_tvOS plug-in. nil disables IMA client-side ads. In the initializer, the parameter is named imaClientSideHandler.
imaDaiProviderImaDaiProviderType?nilGoogle IMA DAI provider, available in the DivaImaAdvertisement_tvOS plug-in. nil disables IMA DAI.
imaDaiAdTagParameters[String: String][:]Overrides a limited set of Google IMA DAI ad tag parameters on the stream request. See the Google IMA DAI documentation.
logLevelDivaLogLevel.noticeMinimum level of the DIVA Player logs: .debug, .info, .notice, .error or .fault.
sessionIdStringUUID().uuidStringID of this DIVA Player instance's lifecycle. A new ID is created for every instance and discarded when the player is removed from memory.
timelineIconThresholdUInt29Distance, in points, under which colliding timeline icons are grouped. 0 disables grouping.
metadataWaitConfigurationMetadataWaitService.Configuration.withDefaultPendingMetadata()Used by DivaTV.startWaitingForMetadata(), which suspends until the listed playback metadata is received or the timeout expires. Fields: waitForMetadata (Bool), timeoutMilliseconds (Int?, nil waits with no timeout) and pendingMetadata ([String], the metadata keys to wait for). The default waits for the default metadata list, with a 10-second timeout.
liveToVodTransitionModeLiveToVodTransitionMode.endOfPlayWhat the viewer sees when the live event being watched is finalized into a VOD: .endOfPlay, .restartFromZero or .customNotifier. Available from 5.12.6. See Configure the live-to-VOD transition.

Callbacks​

All callbacks are optional and default to nil.

PropertyTypeDescription
onVideoError(VideoError, SWVideoMetadataCleanModel?) async -> VoidCalled when a video error happens, with the error and the metadata of the video, if available. See Errors.
onAnalyticEvent(AnalyticsEvent) async -> VoidCalled for every analytics event. See Analytics for the list of events.
onMediaAnalyticsUpdate(MediaAnalyticsUpdate) async -> VoidExposes low-level media player events, to integrate media analytics providers such as Conviva or YOUBORA. See Media analytics and How media analytics updates are delivered.
onExit(Bool) async -> VoidCalled when the player is about to close.
onPreferredAudioTrack(String) async -> VoidCalled when the user selects an audio track, with the track ID.
onPreferredCCTrack(String) async -> VoidCalled when the user selects a closed caption track, with the track ID.
onVideoEnd(String) async -> VoidCalled when a video ends, with its video ID.
onPlaybackSession@Sendable (String) async -> VoidCalled when the playback session changes, with the playback session ID.
onMediaListItemClick(SWMediaListItemCleanModel) async -> VoidCalled when the user selects an item in a media list.

Full configuration example​

var config = DivaTVConfiguration(
// Mandatory
dictionary: dictionary,
settings: settings,
videoId: videoId,
videoMetadataProvider: ExampleVideoMetadataProvider(),
// Optional
videoPlaceholderThumbnail: UIImage(named: "placeholder"),
customFairplayResourceLoader: fairplayResourceLoader,
defaultAudioTrack: "English",
defaultCCTrack: "English",
deepLinkType: .relative,
deepLinkValue: "600000",
entitlementProvider: entitlementProvider,
embedMode: .fullscreen,
hdrMode: false,
imaClientSideHandler: ImaClientSideProvider(),
imaDaiAdTagParameters: ["npa": "1"],
imaDaiProvider: ImaDaiProvider(),
logLevel: .notice,
timelineIconThreshold: DivaTVConfiguration.Constants.defaultTimelineIconThreshold,
liveToVodTransitionMode: .endOfPlay
)

config.onVideoError = { error, videoMetadata in
print("[VideoError] \(error) videoId: \(videoMetadata?.videoId ?? "unknown")")
}
config.onMediaAnalyticsUpdate = { update in
await ConvivaAnalytics.shared.handle(update)
}
config.onExit = { [weak self] _ in
self?.dismiss(animated: true)
}

Task { @MainActor [weak self] in
guard let self else { return }
let diva = await DivaTV(configuration: config)
self.diva = diva
self.present(diva.playerViewController, animated: true)
}

Differences between iOS and tvOS​

PropertyiOS (DivaConfiguration)tvOS (DivaTVConfiguration)
settingsError, networkError✓–
params✓–
maxBitratePreferences✓–
highlightsMode✓–
onCustomActionResponse, visibilityUpdates✓–
videoPlaceholderThumbnail–✓
imaClientSideProvider, imaDaiProvider–✓
metadataWaitConfiguration–✓
IMA DAI ad tag parametersdaiImaAdTagParametersimaDaiAdTagParameters
logLevel default.debug.notice
timelineIconThreshold default2229
onVideoError, onPreferredAudioTrack, onPreferredCCTrackSynchronous closuresasync closures

VideoMetadataProvider protocol​

DIVA Player calls videoMetadataProvider to get the VideoMetadata of a video: when it opens the video, and again when it needs fresh metadata (for example, to follow a live video).

public protocol VideoMetadataProvider {
func requestVideoMetadata(
videoId: String,
currentVideoMetadata: SWVideoMetadataCleanModel?,
playbackState: DivaModel.PlaybackState
) async throws -> SWVideoMetadataCleanModel
}
  • videoId: ID of the video to open.
  • currentVideoMetadata: the metadata DIVA Player is using, or nil on the first request.
  • playbackState: what the viewer expects to see:
    • hdrType: the video type (HDR or SDR) requested, used with hdrMode.
    • chromecastMode: whether the video is (or is about to be) streamed via Chromecast. Always false on tvOS.
    • airplayActive: whether the video is (or is about to be) streamed via AirPlay. Always false on tvOS.

Throw an error when the metadata can't be returned, ideally a DivaModel.VideoMetadataProviderError (.noData, .decodingDataError, .invalidUrl, .invalidServerResponse or .other(message:)).

See the Basic instantiation code for a sample implementation.

How media analytics updates are delivered​

For each player instance, onMediaAnalyticsUpdate works as follows:

  • Updates are delivered one at a time, in order, never concurrently, on a background executor (not the main thread). If you update the UI, switch to the main actor yourself. Updates from different player instances that share the same closure (for example, the iOS modal player or multi-video) aren't serialized with each other.
  • DIVA Player doesn't wait for the callback to return. Do the work inside the callback: wrapping it in your own Task loses the ordering.
  • Return quickly. While a slow callback holds up delivery, frequent updates (bitrate, buffering, rate, seek, play/pause, duration, AirPlay status, repeated .videoLoaded) are merged into the latest one; lifecycle updates are kept, in order. When the backlog is very large, new updates that can't replace one of the same kind are dropped, except .videoClosed. Merged start/end, play/pause and AirPlay on/off pairs may arrive unbalanced.
  • On exit, DIVA Player waits up to 2 seconds for queued updates, .videoClosed included, before calling onExit. After that, queued updates are dropped, except .videoClosed, which is delivered once the running callback returns.
  • iOS: .videoClosed is also sent when the video switches, so it doesn't mean the session ended. tvOS: on exit, .videoClosed is the last update delivered.