Linear Channels / FAST
Methods
changeChannelUrl
function changeChannelUrl(nativeId: string, params: ChannelParams): Promise<string>;
Hands the player of the <Video nativeID={nativeId}> to the SDK and resolves with the local proxy URL to play instead of params.videoUrl.
The <Video> must already be mounted on the original URL: react-native-video only builds its player once a source is set, and the SDK needs that instance to pick an adapter. Waiting for onLoad is the reliable signal.
| Parameter | Type | Description |
|---|---|---|
| nativeId | string | The nativeID of the <Video> to hand over |
| params | ChannelParams | Channel and ad configuration |
ChannelParams
| Field | Type | Description |
|---|---|---|
| videoUrl | string | Original playback URL |
| adTagUrl | string | Ad tag URL issued by an ad server |
| channelId | string | Channel ID Channel IDs must be registered in the FLOWER backend system |
| playerType | PlayerType | (Optional) Player library owning the view. Defaults to 'react-native-video'. |
| extraParams | StringMap | (Optional) Additional information pre-agreed for targeting |
| adTagHeaders | StringMap | (Optional) HTTP headers added to ad requests |
| channelStreamHeaders | StringMap | (Optional) HTTP headers added to requests for the original stream |
| prerollAdTagUrl | string | (Optional) Ad tag URL for a pre-roll break, played before the channel itself starts |
export type ChannelParams = {
videoUrl: string;
adTagUrl: string;
channelId: string;
playerType?: PlayerType;
extraParams?: StringMap;
adTagHeaders?: StringMap;
channelStreamHeaders?: StringMap;
prerollAdTagUrl?: string;
};
Rejects when no view carries that nativeID, or when its player has not been built yet.
prerollAdTagUrl
With prerollAdTagUrl, the SDK plays a channel pre-roll before the channel itself starts:
- The promise still resolves with the proxy URL right away. Hold it: do not set it as the source yet.
- The SDK starts the pre-roll by itself —
prepare, thenplay— on its own ad player in the overlay, and pauses the content player while it runs. The app does not callplayfor it. - When the pre-roll ends, the SDK sends
completed. Set the held proxy URL as the source there. - When the pre-roll tag returns no ad, or the request or playback fails, the SDK still sends
completed, nevererror, so the channel still starts. - Each
changeChannelUrl()call stops the session that was running for thatnativeId, a pre-roll still playing included, and requests the pre-roll of the new call. OmitprerollAdTagUrlto start without one. - If the channel (
channelId) has not changed, the pre-roll is skipped. CallingchangeChannelUrl()again without a channel change — a restart after anerror, for one — skips the pre-roll even withprerollAdTagUrl, and sendscompletedright after the promise resolves, the same way as a pre-roll with no ad.
See Pre-roll Ads.
stop
Stops the current ad break for one channel. Playback of the content itself continues. See stop.
After an error event, stop() is the first half of a channel restart: end the ad session, then call changeChannelUrl() again with the same parameters as the first start, prerollAdTagUrl included, and play the new proxy URL it returns the same way as the first time. See Recovering from an Error.
Work Process
- Mount
<Video nativeID="…">on the original stream URL soreact-native-videobuilds its player. - Subscribe to ad events with
addAdEventListenerForif your app needs to react to ad playback. - Once
onLoadfires, callchangeChannelUrl()with thatnativeID. - Swap the
<Video>source to the returned proxy URL. The player is reused, not rebuilt. WithprerollAdTagUrl, hold the proxy URL and swap it in on thecompletedevent that ends the pre-roll. - On an
errorevent,await stop(nativeId), then repeat steps 3–4: a newchangeChannelUrl()with exactly the same parameters,prerollAdTagUrlincluded, and its new proxy URL handled as in step 4. The channel has not changed, so the pre-roll is skipped (seeprerollAdTagUrl). Cap the number of restarts so a channel that keeps failing does not loop. - Call
releasewhen the<Video>unmounts.
// arg0: nativeId, the nativeID of the <Video> to hand over
// params.videoUrl: original Linear TV stream url
// params.adTagUrl: url from the flower system
// You must file a request to Anypoint Media to receive an adTagUrl.
// params.channelId: unique channel id in your service
// params.extraParams: (Optional) values you can provide for targeting
// params.adTagHeaders: (Optional) values included in headers for ad requests
// params.channelStreamHeaders: (Optional) values included in headers for the channel stream
// params.prerollAdTagUrl: (Optional) ad tag url for a pre-roll break
const proxyUrl = await changeChannelUrl('channel-1', {
videoUrl: 'https://XXX',
adTagUrl: 'https://ad_request',
channelId: '100',
extraParams: {genre: 'horror'},
adTagHeaders: {'custom-ad-header': 'custom-ad-header-value'},
channelStreamHeaders: {'custom-stream-header': 'custom-stream-header-value'},
prerollAdTagUrl: 'https://preroll_ad_request',
});
// With a prerollAdTagUrl, hold the proxy url and set it as the source on 'completed'.
// Without one, set it right away: setSourceUri(proxyUrl).
pendingProxyUrl.current = proxyUrl;