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 pre-roll ads

When prerollAdTagUrl is set, the SDK requests a channel pre-roll that plays once before the live stream, in the SDK's own ad player. The method still returns the stream URL right away; load it on the player only after the pre-roll ends (the first onCompleted or onError of a temporary listener). If there is no pre-roll ad, the request fails, or the pre-roll cannot be played, the SDK still calls onCompleted. Each call stops the previous session, including a pre-roll that is still playing, so a channel switch requests the new channel's pre-roll. If the channel has not changed, the pre-roll is skipped: calling changeChannelUrl again without a channel change, for example on a restart after onError, skips it even though prerollAdTagUrl is passed, and calls onCompleted right after the method returns. A restart therefore passes the same parameters as the first start, including prerollAdTagUrl, and holds the returned URL in the same way. 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.

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.
// 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) ad tag URL for pre-roll ads (nil if not needed)
let changedChannelUrl = flowerAdView.adsManager.changeChannelUrl(
videoUrl: "https://XXX",
adTagUrl: "https://ad_request",
channelId: "100",
extraParams: nil,
mediaPlayerHook: mediaPlayerHook,
adTagHeaders: ["custom-ad-header": "custom-ad-header-value"],
channelStreamHeaders: ["custom-stream-header": "custom-stream-header-value"],
prerollAdTagUrl: "https://preroll_ad_request"
)
// With prerollAdTagUrl, do not load changedChannelUrl yet: load it when the pre-roll ends
// (first onCompleted/onError of a temporary listener, on the main thread).
// Without prerollAdTagUrl, load it right away.
player.insert(AVPlayerItem(url: URL(string: changedChannelUrl)!), after: nil)
...
// TODO GUIDE: change extraParams during stream playback
func onStreamProgramChanged(targetingInfo: String) {
flowerAdView?.adsManager.changeChannelExtraParams(extraParams: ["myTargetingKey": targetingInfo]);
}