Skip to main content
AdPlayer and AdgentSDK are the same class. AdgentSDK is exported as an alias for convenience. Most users should use AdgentSDK as the primary import.

Quick Reference

The AdPlayer class provides fault-tolerant video ad playback for Smart TV platforms with:
  • Nuclear Mute strategy for autoplay compatibility
  • Soft-fail autoplay with interactive overlays
  • Remote control key handling
  • Automatic VAST parsing and tracking

Import

import { AdPlayer } from 'adgent-sdk';
// or
import { AdgentSDK } from 'adgent-sdk';
Both imports reference the same class. The AdgentSDK name is recommended for clarity.

Usage

See the AdgentSDK documentation for complete API reference, constructor parameters, methods, and examples.

Example

import { AdPlayer } from 'adgent-sdk';

const player = new AdPlayer({
  container: document.getElementById('ad-container')!,
  vastUrl: 'https://example.com/vast.xml',
  onComplete: () => console.log('Ad finished')
});

await player.init();

Implementation Details

Located in: src/core/AdPlayer.ts:38

Nuclear Mute Strategy

The player applies the following attributes to the video element for maximum TV compatibility:
{
  muted: true,
  playsinline: true,
  autoplay: true,
  'webkit-playsinline': true
}
See src/core/AdPlayer.ts:173 for the complete video element creation logic.

Autoplay Fallback

When video.play() fails (common on some TV platforms), the player:
  1. Catches the rejection (src/core/AdPlayer.ts:276)
  2. Shows an interactive overlay with a play button (src/core/AdPlayer.ts:287)
  3. Waits for user interaction to start playback
This prevents crashes and provides a graceful degradation path.

Key Handling

The player captures remote control keys and normalizes them using PlatformAdapter:
  • Enter: Start ad (if waiting) or skip (if available)
  • Back: Close or skip ad
  • Play/Pause: Control playback
See src/core/AdPlayer.ts:687 for the key action handler.

Constructor

See AdgentSDK Constructor

Methods

MethodDescriptionReference
init()Initialize SDK and fetch VASTAdgentSDK.init()
skip()Skip the adAdgentSDK.skip()
mute()Mute videoAdgentSDK.mute()
unmute()Unmute videoAdgentSDK.unmute()
on(listener)Add event listenerAdgentSDK.on()
getState()Get current stateAdgentSDK.getState()
destroy()Clean up resourcesAdgentSDK.destroy()

See Also

Build docs developers (and LLMs) love