Ad Events
Ad events replace the FlowerAdsManagerListener interface of the native SDKs. Instead of implementing a listener object, you subscribe to a stream of AdEvent values.
Every event carries the nativeId of the <Video> it belongs to, which is what keeps several players apart.
Subscribing
addAdEventListener
function addAdEventListener(listener: (event: AdEvent) => void): EmitterSubscription;
Subscribes to ad events from every session. Use event.nativeId to tell them apart.
addAdEventListenerFor
function addAdEventListenerFor(
nativeId: string,
listener: (event: AdEvent) => void,
): EmitterSubscription;
Subscribes to ad events from one session only. Events for other nativeId values are filtered out.
Both return a subscription — call remove() on it when the component unmounts:
useEffect(() => {
const subscription = addAdEventListenerFor(nativeId, event => {
// …
});
return () => subscription.remove();
}, [nativeId]);
Event subscriptions are independent of release. Releasing a session does not remove listeners you added yourself.
AdEvent
AdEvent is a discriminated union on the event field, so narrowing on it gives you the payload fields:
export type AdEvent = {nativeId: string} & (
| {event: 'adBreakPrepare'; adCount: number}
| {event: 'prepare'; adDurationMs: number}
| {event: 'play'}
| {event: 'adPlay'; adId: string; durationMs: number}
| {event: 'completed'}
| {event: 'error'; message: string | null}
| {event: 'adUserAction'; action: string; adId: string}
| {event: 'adBreakSkipped'; reason: number}
);
addAdEventListenerFor(nativeId, event => {
switch (event.event) {
case 'prepare':
console.log(`break ready, ${event.adDurationMs}ms`); // adDurationMs is in scope
break;
case 'adPlay':
console.log(`ad ${event.adId} started`); // adId is in scope
break;
}
});
Events
adBreakPrepare
Dispatched when the ad manifest is loaded for interstitial or VOD ads.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| adCount | number | Number of ads loaded for the break |
prepare
Dispatched when the ad break is loaded for interstitial or VOD ads (for a VOD mid-roll, when the content reaches the break position). This is where the app calls play. For an interstitial or inline break, the app also pauses its content here. For a VOD break, the app pauses nothing here: a pre-roll arrives while the app still holds the content before its first start, and for a mid-roll the SDK pauses the content itself.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| adDurationMs | number | Total ad break duration in milliseconds |
play
Dispatched when ad playback starts.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
adPlay
Dispatched when each individual ad unit begins playback.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| adId | string | Ad id specified in the VAST response. An empty string when the response carried none. |
| durationMs | number | Duration of this ad in milliseconds |
completed
Dispatched when ad playback ends. For inline breaks, this is where the app resumes its content. For VOD, the first completed is where the app starts the content it has been holding — the SDK sends it even when there is no pre-roll, the ad response is empty or the request fails. After a VOD mid-roll, the SDK resumes the content itself.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
error
Dispatched when any error happens in the Flower SDK.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| message | string | null | Error message, when the SDK supplied one |
An error during an inline break leaves your content paused, because pausing it was your app's doing. Resume it from this branch as well as from completed, or the viewer is left on a frozen frame.
error is sent when an ad fails to play. When content playback stops and the SDK cannot recover it, error is sent with a message starting with playback unrecoverable (not reported on iOS with playerType: 'bitmovin'). On Android it is also sent for an internal SDK error. A VOD ad request that fails, times out or returns no ads ends with completed, not error.
What to do on error depends on the kind of session:
- Linear TV / FAST, for every
errorincludingplayback unrecoverableand an internal SDK error: end the ad session withawait stop(nativeId), then start the channel over — a newchangeChannelUrl()with exactly the same parameters as the first start,prerollAdTagUrlincluded, and the new proxy URL it returns handled the same way as the first time. The channel has not changed, so the pre-roll is skipped; see Recovering from an Error. - VOD, by where the content is. Never stop, seek or re-source the content here.
completedmay also arrive for the failed break, in either order.- Not started yet (pre-roll): start the held content, exactly as on
completed. - Started and not ended (mid-roll): the SDK has normally brought the content back already; resume it as a safety net —
videoRef.current?.resume()(Bitmovin:player.play()), harmless if it is already playing. - Ended (post-roll): nothing to resume — playback is over.
playback unrecoverable: the content itself stopped. Reload it or show an error.
- Not started yet (pre-roll): start the held content, exactly as on
- Inline: resume your content and call
stop(nativeId), as oncompleted.
adUserAction
Dispatched when the user interacts with the ad.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| action | string | User action type.learn_more: the user clicked the learn-more / click-through area.skip: the user pressed the skip button. |
| adId | string | Ad id the action was performed on |
adBreakSkipped
Dispatched when an ad break is skipped.
| Field | Type | Description |
|---|---|---|
| nativeId | string | The session the event belongs to |
| reason | number | Code describing why the break was skipped.0: Unknown1: No Ad2: Timeout3: Error4: Not Initialized (the ad request was not sent because the SDK had not finished initializing, e.g. right after initialization) |