IPlayerClient instances in the UI layer communicate with VideoPlayer instances in a separate service layer via JavaScript Interface (JSI)-based inter-process communication (IPC). You’ll set up a dual-player architecture with a main player client for content and an ad player client that takes over a shared video surface during ad breaks.
The examples in this tutorial demonstrate pre-buffered ads for seamless ad transitions. For background on CSAI concepts, techniques, and sync strategies, see Client-side ad insertion in Vega.
In this tutorial, you learn how to:
- Set up player client references and imports
- Detect an ad marker and pre-initialize the ad player client
- Wait for the ad to buffer, then pause main content
- Switch the video surface and play the ad
- Return to main content after the ad ends
Prerequisites
- Vega development environment set up
- Vega SDK v0.22 or later
@amazon-devices/kepler-player-clientand@amazon-devices/kepler-player-serverpackages installed- Main content player client already initialized and connected to the service
- Basic knowledge of React Native and TypeScript
Set up player client references
Import the required packages and create refs for the main player client, ad player client, and session IDs.Detect the ad marker and pre-initialize the ad player client
When the position listener detects an upcoming ad break, pre-initialize the ad player client withautoPlay=false and register listeners to know when the ad is buffered and when it ends.
- Set up a position listener to detect upcoming ad breaks.
-
Create the ad player client initialization function. Register a status listener to detect the READY and ENDED states. On platforms where
IPlayerSessionState.READYis not available, the service sends aplayerReadymessage as a fallback.

