Skip to main content
Version: 11.8.0

How do you know when a stream or an advertisement is playing on Web?

This guide explains how to determine programmatically when the player is playing, and whether it is playing a stream or a client-side advertisement. This is useful when you want different behavior, or a different UI, for content and for advertisements.

The playing event tells you when content or an advertisement starts playing. Its event handler is the right place to check whether an advertisement is playing.

This approach only works for client-side advertisements, not for server-side advertisements.

Usage

The Web SDK exposes whether an advertisement is playing through player.ads.playing.

player.addEventListener('playing', (event) => {
const adIsPlaying = player.ads.playing;
console.log('PLAYING', adIsPlaying ? 'Advertisement' : 'Content', event);
});