OptiViewAds

class OptiViewAds(config: OptiViewAdsConfig, renderer: AdRenderer, manifestSource: ManifestSource, ticker: SchedulerTicker, scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default), clock: Clock = systemClock)

The OptiView Ads SDK entry point: one instance per content player, living as long as the player. It polls the Break Manifest of the current session, schedules the breaks against the player's timeline through the configured PlayerAdapter, plays them through the AdRenderer, and reports what happens on the event stream (addEventListener) and the diagnostics stream (onDiagnostic, exportDiagnostics).

Typical use: construct it once with an OptiViewAdsConfig and the Android runtime's OverlayAdRenderer, startSession for each piece of content, endSession when the content stops, and destroy when the player goes away.

Parameters

config

Fixed configuration for the lifetime of the instance.

renderer

Plays the ads; the Android runtime's OverlayAdRenderer.

manifestSource

Fetches and polls the Break Manifest; normally HttpManifestSource.

ticker

Drives break scheduling; normally CoroutineSchedulerTicker.

scope

The coroutine scope the SDK works in; the default is fine for apps.

clock

The time source; the default is the system clock (tests inject a fake).

Constructors

Link copied to clipboard
constructor(config: OptiViewAdsConfig, renderer: AdRenderer, manifestSource: ManifestSource, ticker: SchedulerTicker, scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default), clock: Clock = systemClock)

Types

Link copied to clipboard
object Companion

Static information about the SDK.

Properties

Link copied to clipboard

Return the current playback-gated ad break status snapshot. Useful for polling when an adbreakstatus event was missed, or for rendering an initial badge before any event fires. Mirrors the web getAdBreakStatus().

Link copied to clipboard

Unified volume (0-1) across content and ad playback. See muted.

Functions

Link copied to clipboard

Subscribe to an SDK event.

Link copied to clipboard
fun clickAd(): String?

Report a click on the ad currently on screen and emit the public adclick event carrying the asset's declared interaction.clickThrough URL (if any). Called by the renderer on a viewer tap, or programmatically by the application (e.g. a custom "visit advertiser" button). The SDK deliberately does NOT open the URL — that is the application's decision. Returns the clickThrough URL when a click was registered, null otherwise. Mirrors the web/iOS clickAd().

Link copied to clipboard
fun destroy()

Clean up all resources. Call when the SDK is no longer needed.

Link copied to clipboard

Stop monetization for the current content.

Link copied to clipboard

Produce a self-contained, redacted diagnostic report for support / AI tooling.

Link copied to clipboard

The current ad-break status snapshot, the same one AdBreakStatusEvent carries.

Link copied to clipboard

What the SDK currently has on the player surface — see PresentationState.

Link copied to clipboard

Whether an ad is currently playing.

Link copied to clipboard

Whether the content player is in picture-in-picture — as observed by the renderer's own Activity watcher, or as last reported through setPictureInPicture where that watcher could not attach.

Link copied to clipboard

Whether a session is currently active.

Link copied to clipboard

Unsubscribe from the structured diagnostic stream.

Link copied to clipboard

Subscribe to the structured diagnostic stream.

Link copied to clipboard
fun pause()

Pause content playback. No-op while a content-locking ad break is active.

Link copied to clipboard
fun play()

Start or resume content playback. No-op while a content-locking ad break is active.

Link copied to clipboard

Unsubscribe from an SDK event.

Link copied to clipboard
fun seek(time: Double)

Seek to time seconds. Blocked during breaks with controls.snapback. No-op with no session.

Link copied to clipboard

Tell the SDK whether the content player is in picture-in-picture.

Link copied to clipboard

Skip the in-progress ad break, honoring the manifest's skip policy: the break must declare controls.skipOffset and at least that many seconds of the break must have elapsed. Returns true when the skip was applied (the break cuts to content, emitting the balanced adend + adbreakend), false when suppressed (no active break, no skip control, or before the offset). Use getAdBreakStatus to drive a "Skip in Ns" affordance. Mirrors the web/iOS skipAd().

Link copied to clipboard
suspend fun startSession(config: SessionConfig)

Start monetization for a piece of content. Begins manifest polling and (if configured) GAM session init. Ends any previously active session first.

Link copied to clipboard

Merge macros into the asset-parameter macros of the active session. Each name replaces the previous value for that name; other names stay. A null value removes the customer macro so the built-in $OPTIVIEW_* value (if any) applies again. When a GAM stream is active the effective ad tag parameters are resolved again and pushed to IMA; VAST tag URLs use the new values on the next ad request. No-op (with a warning) without an active session.

Link copied to clipboard

Merge explicit-value asset-parameter macros into the active session. A callback returning com.dolby.optiview.ads.core.AssetParameterMacroValue.Empty omits the containing parameter (or cust_params pair); a null entry removes the customer macro.

Link copied to clipboard

Replace the live-update layer of the asset parameters on the active session. Applies to future ad breaks — no re-initialization needed.