Skip to main content

Linear Channels / FAST

Methods​

FlowerAdsManager.changeChannelUrl​

The function above allows you to dynamically change the stream URL of a live broadcast. The parameters are described below:

ParameterTypeDescription
videoUrlstringOriginal playback URL
adTagUrlstringAd tag URL issued by an ad server
channelIdstringChannel ID
Channel IDs must be registered in the FLOWER backend system
extraParamsmapExtra information which is agreed upon for targeting (null for no extra information)
mediaPlayerHookMediaPlayerHookAn object implementing an interface that returns a video player
adTagHeadersmap(Optional) HTTP header information to be added when requesting an ad
channelStreamHeadersmap(Optional) HTTP header information to be added when requesting the original media stream
prerollAdTagUrlstring(Optional) Ad tag URL issued by the ad server for the channel pre-roll, an ad played once before the live stream starts (null for no pre-roll). See Pre-roll Ads.

FlowerAdsManager.changeChannelExtraParams​

This function above allows you to change extraParams, which is additional targeting information, during a live broadcast. The parameter is described below:

ParameterTypeDescription
extraParamsmapAdditional targeting information agreed upon beforehand

FlowerAdsManager.stop​

This method stops the playback of linear channels. There are no parameters.

Pre-roll Ads​

When prerollAdTagUrl is set, changeChannelUrl() returns the stream URL right away and the SDK requests the pre-roll and plays it in its own ad player. Do not load the returned URL until the pre-roll ends: register a temporary listener and start the stream on its first onCompleted() (or onError()). The SDK reports onCompleted() also when there is no pre-roll ad or the pre-roll fails. If the channel has not changed, the pre-roll is skipped: calling changeChannelUrl() again without a channel change skips the pre-roll even if prerollAdTagUrl is passed and reports onCompleted() right after the call returns, so a restart after onError passes the same parameters, including prerollAdTagUrl, and starts the stream in the same way. A channel change (A → B → A) plays the pre-roll again. enterChannel() has no pre-roll parameter. For the full flow and example, see Manual Player Control.

Work Process​

  1. Insert replacement ads at the correct timing, consulting “Ad UI Declaration”
  2. If you need additional processing during ad playback, you can listen for events corresponding to ad playbacks or finishes by implementing the FlowerAdsManagerListener interface.
  3. Finally, change the original streaming URL by using FlowerAdsManager.changeChannelUrl and then send it to the player.
  4. (Optional) If targeting information changes during streaming, update the SDK with the new information using FlowerAdsManager.changeChannelExtraParams.

Java​

private void playLinearTv() {
// TODO GUIDE: change original LinearTV stream url by adView.adsManager.changeChannelUrl
// arg0: videoUrl, original LinearTV stream url
// arg1: adTagUrl, url from flower system
// You must file a request to Anypoint Media to receive a adTagUrl.
// arg2: channelId, unique channel id in your service
// arg3: extraParams, values you can provide for targeting
// arg4: mediaPlayerHook, interface that provides currently playing segment information for ad tracking
// arg5: adTagHeaders, (Optional) values included in headers for ad request
// arg6: channelStreamHeaders, (Optional) values included in headers for channel stream request
// arg7: prerollAdTagUrl, (Optional) null for no pre-roll. With a pre-roll, load the returned URL
// only after the pre-roll ends (see Pre-roll Ads).
String changedChannelUrl = flowerAdView.getAdsManager().changeChannelUrl(
"https://XXX",
"https://ad_request",
"100",
createMap("custom-param", "custom-param-value"),
mediaPlayerHook,
createMap("custom-ad-header", "custom-ad-header-value"),
createMap("custom-stream-header", "custom-stream-header-value"),
null
);
player.setMediaItem(MediaItem.fromUri(changedChannelUrl));
}

// TODO GUIDE: change extraParams during stream playback
public void onStreamProgramChanged(String targetingInfo) {
flowerAdView.getAdsManager().changeChannelExtraParams(createMap("myTargetingKey", targetingInfo));
}

private Map<String, String> createMap(String key, String value) {
Map<String, String> map = new HashMap<>();
map.put(key, value);
return map;
}

Kotlin​

private fun playLinearTv() {
// TODO GUIDE: change original LinearTV stream url by adView.adsManager.changeChannelUrl
// arg0: videoUrl, original LinearTV stream url
// arg1: adTagUrl, url from flower system
// You must file a request to Anypoint Media to receive a adTagUrl.
// arg2: channelId, unique channel id in your service
// arg3: extraParams, values you can provide for targeting
// arg4: mediaPlayerHook, interface that provides currently playing segment information for ad tracking
// arg5: adTagHeaders, (Optional) values included in headers for ad request
// arg6: channelStreamHeaders, (Optional) values included in headers for channel stream request
// arg7: prerollAdTagUrl, (Optional) null for no pre-roll. With a pre-roll, load the returned URL
// only after the pre-roll ends (see Pre-roll Ads).
val changedChannelUrl = flowerAdView.adsManager.changeChannelUrl(
"https://XXX",
"https://ad_request",
"100",
mapOf("custom-param" to "custom-param-value"),
mediaPlayerHook,
mapOf("custom-ad-header" to "custom-ad-header-value"),
mapOf("custom-stream-header" to "custom-stream-header-value"),
null
)
player.setMediaItem(MediaItem.fromUri(changedChannelUrl))
}

// TODO GUIDE: change extraParams during stream playback
fun onStreamProgramChanged(targetingInfo: String) {
flowerAdView.adsManager.changeChannelExtraParams(mapOf("myTargetingKey" to targetingInfo))
}