OptiView Ads SDK
    Preparing search index...

    Class HlsJsAdapter

    The PlayerAdapter for HLS.js, from the @dolby-optiview/ads-sdk-adapter-hlsjs package (peer dependency: hls.js 1.x).

    import Hls from 'hls.js';
    import { HlsJsAdapter } from '@dolby-optiview/ads-sdk-adapter-hlsjs';

    // Content player (pass existing video element)
    const video = document.getElementById('video') as HTMLVideoElement;
    const hls = new Hls();
    hls.loadSource('https://example.com/stream.m3u8');
    hls.attachMedia(video);
    const adapter = new HlsJsAdapter(hls, video);

    // Ad adapter factory (SDK creates a container div and passes it)
    createAdAdapter: (container) => {
    const adVideo = document.createElement('video');
    container.appendChild(adVideo);
    const adHls = new Hls();
    adHls.attachMedia(adVideo);
    return new HlsJsAdapter(adHls, adVideo);
    }

    Implements

    Index
    • Parameters

      • hls: Hls

        The Hls instance that plays the content.

      • videoElement: HTMLVideoElement

        The <video> element hls is attached to.

      Returns HlsJsAdapter

    • get duration(): number

      Total duration of the content in seconds.

      Returns number

    • get isLive(): boolean | null

      Live per the PLAYLIST, not per the media duration.

      video.duration cannot answer this on hls.js: the engine sets it to Infinity for live only when liveDurationInfinity is configured, and that defaults to false — so a live stream normally reports a finite duration equal to the playlist edge. latestLevelDetails carries the real answer, taken straight from the absence of #EXT-X-ENDLIST.

      Cast and optional-chained because latestLevelDetails is newer than the hls.js this adapter must keep compiling against; an older build returns undefined and the core falls back to its duration proxy.

      Returns boolean | null

    • get maxLiveSeekPosition(): number | null

      The closest-to-live position hls.js will actually hold — null on VOD.

      hls.js is the one engine that pre-computes this, so there is no offset arithmetic here: its own hls.liveSyncPosition is already liveEdge - targetLatency, clamped into the seekable window by the latency controller itself.

      The explicit liveness gate is NOT redundant, despite what hls.js's own docstring suggests ("@returns null prior to loading live Playlist"). On VOD the getter returns a NUMBER, not null: targetLatency falls back to liveSyncDurationCount * targetduration (3 x segment duration by default) whenever holdBack is absent, which is exactly the VOD case, and estimateLiveEdge() needs only levelDetails — which VOD has. The result is a plausible-looking position roughly 3 segments from the end of the asset. Handing that to the resume clamp would drag every VOD resume backwards, breaking the one guarantee this feature is supposed to keep: VOD is untouched.

      latestLevelDetails.live is the authoritative flag and is public API.

      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.

      Proxies the element rather than remembering what was written. hls.js drives this property itself when maxLiveSyncPlaybackRate is configured, nudging the rate to hold live latency, and the SDK needs to see that so it can stop competing rather than fight 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 from the HLS manifest (EXT-X-PROGRAM-DATE-TIME).

      Returns Date | null

    • get sourceUrl(): string | null

      The manifest hls.js currently has, read off the engine (hls.url) so it is correct even when the application called loadSource() itself. The element's own src is a blob: MediaSource and cannot be reloaded.

      Returns string | null

    • get supportsParallelBuffering(): boolean

      Whether the content and ad pipelines can buffer in parallel. True whenever HLS.js (MSE) is operational. On Web, false prevents continued content playout during a break because the two pipelines cannot remain buffered concurrently.

      Returns boolean

    • 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>

    • Detached prefetch for the single-decoder preload strategy.

      Spins up a throwaway HLS.js instance with startFragPrefetch that parses the manifest and fetches the first fragment WITHOUT attaching media — so no second MediaSource / decoder is engaged. The raw responses land in the browser HTTP cache; the instance is destroyed once the first fragment is loaded (or on error/timeout). Best-effort: never rejects.

      Parameters

      • url: string

      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.

      The lowest rendition is selected through nextLevel, which hls.js documents as taking effect without interrupting the fragment being decoded. currentLevel would flush the whole buffer and stall the content timeline. The argmin is computed because hls.js does not sort its level array by bitrate first.

      Parameters

      • quality: "lowest" | null

      Returns boolean