PIP Mode Support
Ads are not played in PIP (Picture-in-Picture) mode by default, and the SDK does not detect by itself that the user has left the app. Two functions control this, both imported from the package root:
import {
notifyUserLeftApp,
setIgnoreAdBreakInPIPMode,
} from '@anypoint/flower-sdk-react-native';
Both apply to the whole app, not to one nativeId.
Methods
notifyUserLeftApp
function notifyUserLeftApp(hasLeftApp: boolean): Promise<void>;
Tells the SDK the user left the app (true) — to the home screen, to another app, or with the video moved to a PIP window — or came back to it (false). Report it whether or not the app enters PIP.
| Parameter | Type | Description |
|---|---|---|
| hasLeftApp | boolean | true when the user leaves the app, false when the user comes back |
notifyPictureInPictureModeChanged(isInPictureInPictureMode) is deprecated and replaced by notifyUserLeftApp. Existing calls keep working.
setIgnoreAdBreakInPIPMode
function setIgnoreAdBreakInPIPMode(ignore: boolean): Promise<void>;
Selects how ads are played. The default is true. Call it before requesting ads — the ad player is chosen when ads are requested.
| Value | Ad player | Ads in PIP mode |
|---|---|---|
true (default) | VOD and inline breaks play in the SDK's own ad player, in the overlay over your <Video>. | Not supported. An ad playing when the user leaves the app is paused, and mid-roll or post-roll breaks are not requested until the user comes back. |
false | VOD breaks play inside your <Video>'s own player (react-native-video on Android and iOS, Bitmovin on Android): the ads are put in front of the content, and the content comes back afterwards. Inline breaks, and VOD breaks with Bitmovin on iOS, still play in the SDK's own ad player. | Supported for VOD breaks on the app's player. Ads keep playing in PIP mode. |
Report both moments, the user leaving the app and coming back, through notifyUserLeftApp, whether or not the app enters PIP. The SDK does not detect either by itself, with any playerType.
Ads in PIP Mode (Default)
Ads are not supported in PIP mode by default. While an ad is playing, keep the content out of PIP, because PIP mode could otherwise be used to bypass the ad. Since the app then does not enter PIP, the SDK learns that the user has left only if the app tells it — that is why the app reports leaving and returning through notifyUserLeftApp, whether or not it enters PIP, so that the ad pauses when the user leaves and resumes on return.
- When the app calls
notifyUserLeftApp(true)while an ad is playing, the SDK pauses the ad and hides the ad UI. While the ad is paused, its progress does not advance. - When the app calls
notifyUserLeftApp(false), the ad resumes from where it stopped and plays to completion. - Until the user comes back, mid-roll and post-roll breaks are not requested.
- Linear TV ads spliced into the stream are not affected by this option. They keep playing while the user is away, and only the ad UI is hidden. A channel pre-roll (
prerollAdTagUrl) is paused and resumed in the same way as VOD ads.
Which window goes into PIP is decided by the OS and the app, not by the SDK: on iOS, the player layer the PIP controller is attached to — the content player; on Android, the whole Activity. While an ad is playing, do not let the content <Video> enter PIP.
React Native's AppState reports the user leaving (background) and coming back (active), with or without PIP. Ignore inactive, a transient state such as the app switcher being opened.
import React, {useEffect, useState} from 'react';
import {AppState} from 'react-native';
import Video from 'react-native-video';
import {
addAdEventListenerFor,
notifyUserLeftApp,
} from '@anypoint/flower-sdk-react-native';
export function VodPlayer({nativeId, contentUrl}: {nativeId: string; contentUrl: string}) {
const [adPlaying, setAdPlaying] = useState(false);
useEffect(() => {
const subscription = addAdEventListenerFor(nativeId, event => {
if (event.event === 'play') {
setAdPlaying(true);
} else if (event.event === 'completed' || event.event === 'error') {
setAdPlaying(false);
}
});
return () => subscription.remove();
}, [nativeId]);
// Report the user leaving and coming back, whether or not the app enters PIP.
useEffect(() => {
const subscription = AppState.addEventListener('change', state => {
if (state === 'background') {
notifyUserLeftApp(true).catch(() => {});
} else if (state === 'active') {
notifyUserLeftApp(false).catch(() => {});
}
});
return () => subscription.remove();
}, []);
return (
<Video
nativeID={nativeId}
source={{uri: contentUrl}}
// Keep the content out of PIP while an ad plays.
enterPictureInPictureOnLeave={!adPlaying}
/>
);
}
notifyUserLeftApp is app-wide, so a single AppState subscription is enough for the whole app; it does not have to live in the player component.
Supporting Ads in PIP Mode
Conversely, to support ads in PIP mode as well for more ad inventory (setIgnoreAdBreakInPIPMode(false)), the app needs to pay attention to how it handles player events.
// Play ads in the app's player so that they keep playing in PIP mode.
await setIgnoreAdBreakInPIPMode(false);
A VOD break plays inside your player in this mode for:
react-native-videoon Android and iOSplayerType: 'bitmovin'on Android
playerType: 'bitmovin' on iOS always uses the SDK's own ad player, and so do inline breaks (requestAd()) on every player — the app still pauses and resumes its content around an inline break.
The rule for the content is the same as in the default mode: hold it paused before its first start, until the first completed or error, and never pause, seek or re-source it after it has started. On an error after a failed mid-roll, the SDK has already put the content back; do not stop, seek or re-source it, but resume it as a safety net (videoRef.current?.resume(), or player.play() with Bitmovin), which is harmless if it is already playing. One ad failure can surface as two error events in this mode. Mark the content ended at the same point where you call notifyContentEnded() (see below), so a post-roll error does not resume it. See VOD Ad Implementation.
How Ads Are Played in Your Player
- When a break starts, the SDK puts the ad items in front of the content in the native player behind your
<Video>, and the player moves to the ads. - When the break ends, the SDK puts the content back as a new player item at the resume point (the interrupted position minus the rewind duration).
Handling Player Events
Because the native player's current item changes around every break, any logic that detects item changes or the end of playback must react only to the content, not to whichever item is current.
react-native-videobinds its observers to the item it loaded. On iOS itsonEnddoes not fire after a break in this mode, and on Android the ended state is also reported around breaks. Do not rely ononEndalone to callnotifyContentEnded(), and call it only once per content.- With
react-native-videoon Android, the position reported after a mid-roll (onProgress'scurrentTime) counts from the resume point, not from the start of the content, because the content comes back clipped. Bitmovin on Android reloads the source at an offset instead, so this does not apply to it. - On iOS, settings applied to the item
react-native-videobuilt (for examplesource.headers, DRM, buffer and bitrate settings, selected audio and text tracks) are not carried over to the item the SDK puts back.
If your app cannot detect the end of the content without these item-bound events, or relies on item-level settings, use the default mode.