OptiView Ads SDK
    Preparing search index...

    Class ShakaAdapter

    The PlayerAdapter for Shaka Player, from the @dolby-optiview/ads-sdk-adapter-shaka package (peer dependency: shaka-player 4 or 5).

    Preferred usage — create the Player WITHOUT passing the video element to the constructor (avoids Shaka's deprecated eager-MediaSource-init path which can interfere with the ad video element's CSS rendering):

    import shaka from 'shaka-player';
    import { ShakaAdapter } from '@dolby-optiview/ads-sdk-adapter-shaka';

    shaka.polyfill.installAll();
    const video = document.getElementById('video') as HTMLVideoElement;
    const player = new shaka.Player(); // ← no video arg

    const adapter = new ShakaAdapter(player, video);
    // player.attach(video) is called automatically inside adapter.load()

    If you pass the video element to the constructor (legacy/deprecated pattern), ShakaAdapter still works — load() re-attaches only when the player is attached elsewhere.

    Implements

    Index
    • get duration(): number

      Total duration of the content in seconds.

      Returns number

    • get isLive(): boolean | null

      Shaka answers this directly, so there is nothing to infer.

      Guarded like every other optional member on ShakaPlayerLike: an integrator may hand us a partial player, and a missing method must degrade to "cannot say" rather than throw inside a break.

      Returns boolean | null

    • get maxLiveSeekPosition(): number | null

      Latest live playback position the player can seek to without moving back to maintain its minimum live offset, in seconds. Return null when unknown or not live; the SDK then leaves the seek target unclamped. Use the player engine's seek limit rather than guessing an offset: HLS.js exposes liveSyncPosition, THEOplayer exposes latencyManager.currentLatency / minimumOffset, and Shaka exposes seekRange() / safeSeekEndOffset.

      Returns number | null

    • get muted(): boolean

      Whether the player is muted.

      Returns boolean

    • set muted(value: boolean): void

      Settable so the SDK can sync mute state between content and ad players.

      Parameters

      • value: boolean

      Returns void

    • get paused(): boolean

      Whether the player is currently paused.

      Returns boolean

    • get playbackRate(): number

      Playback rate, 1 being normal speed.

      Reads the element rather than a remembered value: with streaming.liveSync enabled Shaka adjusts the rate itself to hold its target latency, and the SDK needs to see that so it stops correcting rather than fighting it.

      Returns number

    • set playbackRate(value: number): void

      Playback rate (1 = normal). Used to correct drift while content continues behind an ad with continueContentDuringBreak. Report the engine's current rate, not just the last assigned value, so the SDK can detect changes made by the player's live-latency controller. If omitted, drift is reported but not corrected.

      Parameters

      • value: number

      Returns void

    • get programDateTime(): Date | null

      Program Date Time of the current playback position, anchored on the manifest's EXT-X-PROGRAM-DATE-TIME (getInitialProgramDateTime). Returns null for VOD or when the manifest carries no PDT: Shaka then synthesizes a presentation start (getPresentationStartTime) that trails wallclock by the live delay, which would misplace wallclock breaks — the core's own wallclock fallback is the right answer there, as with the other adapters.

      Returns Date | null

    • get sourceUrl(): string | null

      The manifest Shaka currently has. Shaka attaches a MediaSource, so the element's src is a blob: and cannot be reloaded; getAssetUri() is the real answer and stays right even when the application loaded the source through the player directly.

      Returns string | null

    • get videoElement(): HTMLVideoElement

      The underlying HTMLVideoElement. Exposed so the SDK can pass it to GAM.

      Returns HTMLVideoElement

    • get volume(): number

      Volume level in the range [0, 1].

      Returns number

    • set volume(value: number): void

      Volume in [0, 1]; settable so the SDK can sync it between content and ad players.

      Parameters

      • value: number

      Returns void

    • Load a media source without playing; resolves when it is ready to play. Used to preload ads.

      Parameters

      • url: string

      Returns Promise<void>

    • Resume playback.

      Returns Promise<void>

    • Let go of the <video> so the SDK can play an ad through it (shared-element insertion).

      Shaka does not tolerate sharing: with the player still attached, its MediaSource and the ad engine's compete for the same element, and the ad either aborts outright or loops on its first segment.

      detach() rather than destroy(): the same player instance takes the element back at break end, when the SDK calls load() with the saved content source — and load() re-attaches when it finds the element is no longer Shaka's.

      Returns Promise<void>

    • Seek to a specific time in seconds.

      Parameters

      • time: number

      Returns void

    • Set the requested video quality, or restore the selection in force before the first set. Returns whether an override was applied or an outstanding override was restored.

      Selecting a Shaka variant does not stop ABR, so the lowest request suspends ABR before selecting. clearBuffer is explicitly false, preserving the non-interrupting switch after buffered content has played. Missing optional APIs degrade to no quality change.

      Parameters

      • quality: "lowest" | null

      Returns boolean