Configuration
Before starting
DivaConfiguration(iOS) andDivaTVConfiguration(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,videoIdand VideoMetadata.
This reference describes DIVA Player iOS/tvOS 5.12.6.
iOS: DivaConfiguration
Mandatory properties
| Property | Type | Description |
|---|---|---|
| settings | SWSettingCleanModel | DIVA settings: they set up, enable or disable, and adapt DIVA Player features and UX to your project. See Settings. |
| dictionary | SWDictionaryCleanModel | Localized strings used in the DIVA Player UI, as key/value pairs. See Dictionary. |
| videoId | String | ID of the video to open. DIVA Player passes it to videoMetadataProvider to get the video's metadata. |
| videoMetadataProvider | VideoMetadataProvider | Object DIVA Player calls to get the VideoMetadata of a video. See VideoMetadataProvider. |
Optional properties
| Property | Type | Default | Description |
|---|---|---|---|
| entitlementProvider | EntitlementProvider? | nil | Entitlement 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. |
| customFairplayResourceLoader | CommonFairplayResourceLoader? | nil | FairPlay DRM support. Leave it nil if your streams aren't DRM-protected. |
| settingsError | String | "" | Message shown when the settings can't be used. |
| networkError | String | "" | 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. |
| deepLinkType | Diva.DeeplinkType | .relative | How DIVA Player reads deepLinkValue:• .relative: an offset from the start of the video.• .absolute: a date and time, synchronized with the video's timecodeIn. |
| deepLinkValue | String | "" | 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. |
| defaultAudioTrack | String? | nil | Audio track selected when the video starts. Use the format set by audioSelectionMethod in the general settings. |
| defaultCCTrack | String? | nil | Closed caption track selected when the video starts. Use the format set by closedCaptionSelectionMethod in the general settings. |
| maxBitratePreferences | Double | -1 | Maximum bitrate, in kbps. -1 (or any value ≤ 0) means no limit. Not applied to 360° videos, nor when video quality selection is enabled. |
| hdrMode | Bool | false | Enables 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. |
| highlightsMode | Settings.HighlightsFilters.FilterType? | nil | Starts the player in highlights mode with the given filter: .short, .medium, .long or .live. nil starts normal playback. |
| logLevel | DivaLogLevel | .debug | Minimum level of the DIVA Player logs: .debug, .info, .notice, .error or .fault. |
| embedMode | Diva.EmbedMode | .fullscreen | How 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. |
| timelineIconThreshold | UInt | 22 | Distance, in points, under which colliding timeline icons are grouped. 0 disables grouping. |
| sessionId | String | UUID().uuidString | ID of this DIVA Player instance's lifecycle. A new ID is created for every instance and discarded when the player is removed from memory. |
| liveToVodTransitionMode | LiveToVodTransitionMode | .endOfPlay | What 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.
| Property | Type | Description |
|---|---|---|
| onVideoError | (VideoError, VideoMetadata?) -> Void | Called when a video error happens, with the error and the metadata of the video, if available. See Errors. |
| onAnalyticEvent | (AnalyticsEvent) async -> Void | Called for every analytics event. See Analytics for the list of events. |
| onMediaAnalyticsUpdate | (MediaAnalyticsUpdate) async -> Void | Exposes 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)) -> Void | Called when the user triggers a custom action, with the action ID and the metadata of the current video. |
| onExit | (Bool) async -> Void | Called when the player is about to close. The value is true when the user closed the player. |
| onPreferredAudioTrack | (String) -> Void | Called when the user selects an audio track, with the track ID. |
| onPreferredCCTrack | (String) -> Void | Called when the user selects a closed caption track, with the track ID. |
| onVideoEnd | (String) async -> Void | Called when a video ends, with its video ID. |
| onPlaybackSession | @Sendable (String) async -> Void | Called when the playback session changes, with the playback session ID. |
| onMediaListItemClick | (SWMediaListItemCleanModel) async -> Void | Called when the user selects an item in a media list. |
| visibilityUpdates | (Bool) -> Void | Called 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 passfairPlayCertificateUrl, it's added toparamsasFairPlayCertificateURL.paramsdefaults to["Offline": "true"].DivaConfiguration.forOffline(videoId:localURL:fairplayResourceLoader:sessionId:logLevel:embedMode:params:onExit:onPlaybackSession:onVideoError:)creates the configuration to play a downloaded video fromlocalURL. It reads the settings, dictionary and VideoMetadata saved with the download, and falls back to basic settings when they aren't available. GetlocalURLfromDownloadManager.shared.getDownloadURL(itemKey:).
tvOS: DivaTVConfiguration
Mandatory properties
The initializer takes dictionary before settings.
| Property | Type | Description |
|---|---|---|
| dictionary | SWDictionaryCleanModel | Localized strings used in the DIVA Player UI, as key/value pairs. See Dictionary. |
| settings | SWSettingCleanModel | DIVA settings: they set up, enable or disable, and adapt DIVA Player features and UX to your project. See Settings. |
| videoId | String | ID of the video to open. DIVA Player passes it to videoMetadataProvider to get the video's metadata. |
| videoMetadataProvider | VideoMetadataProvider | Object DIVA Player calls to get the VideoMetadata of a video. See VideoMetadataProvider. |
Optional properties
| Property | Type | Default | Description |
|---|---|---|---|
| videoPlaceholderThumbnail | UIImage? | nil | Placeholder image shown before the video starts. |
| customFairplayResourceLoader | CommonFairplayResourceLoader? | nil | FairPlay DRM support: pass a class that conforms to FairplayResourceLoader. Leave it nil if your streams aren't DRM-protected. |
| defaultAudioTrack | String? | nil | Audio track selected when the video starts. Use the format set by audioSelectionMethod in the general settings. |
| defaultCCTrack | String? | nil | Closed caption track selected when the video starts. Use the format set by closedCaptionSelectionMethod in the general settings. |
| deepLinkType | DivaTV.DeeplinkType | .relative | How DIVA Player reads deepLinkValue: .relative (offset from the start) or .absolute (date and time). |
| deepLinkValue | String | "" | 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. |
| entitlementProvider | EntitlementProvider? | nil | Entitlement 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. |
| embedMode | DivaModel.EmbedMode | .fullscreen | How 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. |
| hdrMode | Bool | false | Enables 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. |
| imaClientSideProvider | ImaClientSideProviderType? | nil | Google 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. |
| imaDaiProvider | ImaDaiProviderType? | nil | Google 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. |
| logLevel | DivaLogLevel | .notice | Minimum level of the DIVA Player logs: .debug, .info, .notice, .error or .fault. |
| sessionId | String | UUID().uuidString | ID of this DIVA Player instance's lifecycle. A new ID is created for every instance and discarded when the player is removed from memory. |
| timelineIconThreshold | UInt | 29 | Distance, in points, under which colliding timeline icons are grouped. 0 disables grouping. |
| metadataWaitConfiguration | MetadataWaitService.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. |
| liveToVodTransitionMode | LiveToVodTransitionMode | .endOfPlay | What 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.
| Property | Type | Description |
|---|---|---|
| onVideoError | (VideoError, SWVideoMetadataCleanModel?) async -> Void | Called when a video error happens, with the error and the metadata of the video, if available. See Errors. |
| onAnalyticEvent | (AnalyticsEvent) async -> Void | Called for every analytics event. See Analytics for the list of events. |
| onMediaAnalyticsUpdate | (MediaAnalyticsUpdate) async -> Void | Exposes 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 -> Void | Called when the player is about to close. |
| onPreferredAudioTrack | (String) async -> Void | Called when the user selects an audio track, with the track ID. |
| onPreferredCCTrack | (String) async -> Void | Called when the user selects a closed caption track, with the track ID. |
| onVideoEnd | (String) async -> Void | Called when a video ends, with its video ID. |
| onPlaybackSession | @Sendable (String) async -> Void | Called when the playback session changes, with the playback session ID. |
| onMediaListItemClick | (SWMediaListItemCleanModel) async -> Void | Called 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
| Property | iOS (DivaConfiguration) | tvOS (DivaTVConfiguration) |
|---|---|---|
settingsError, networkError | ✓ | – |
params | ✓ | – |
maxBitratePreferences | ✓ | – |
highlightsMode | ✓ | – |
onCustomActionResponse, visibilityUpdates | ✓ | – |
videoPlaceholderThumbnail | – | ✓ |
imaClientSideProvider, imaDaiProvider | – | ✓ |
metadataWaitConfiguration | – | ✓ |
| IMA DAI ad tag parameters | daiImaAdTagParameters | imaDaiAdTagParameters |
logLevel default | .debug | .notice |
timelineIconThreshold default | 22 | 29 |
onVideoError, onPreferredAudioTrack, onPreferredCCTrack | Synchronous closures | async 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, ornilon the first request.playbackState: what the viewer expects to see:hdrType: the video type (HDR or SDR) requested, used withhdrMode.chromecastMode: whether the video is (or is about to be) streamed via Chromecast. Alwaysfalseon tvOS.airplayActive: whether the video is (or is about to be) streamed via AirPlay. Alwaysfalseon 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
Taskloses 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,
.videoClosedincluded, before callingonExit. After that, queued updates are dropped, except.videoClosed, which is delivered once the running callback returns. - iOS:
.videoClosedis also sent when the video switches, so it doesn't mean the session ended. tvOS: on exit,.videoClosedis the last update delivered.