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:
- Catches the rejection (src/core/AdPlayer.ts:276)
- Shows an interactive overlay with a play button (src/core/AdPlayer.ts:287)
- 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
| Method | Description | Reference |
|---|
init() | Initialize SDK and fetch VAST | AdgentSDK.init() |
skip() | Skip the ad | AdgentSDK.skip() |
mute() | Mute video | AdgentSDK.mute() |
unmute() | Unmute video | AdgentSDK.unmute() |
on(listener) | Add event listener | AdgentSDK.on() |
getState() | Get current state | AdgentSDK.getState() |
destroy() | Clean up resources | AdgentSDK.destroy() |
See Also