Skip to content

Examples ​

Three Roku reference apps show a complete integration of TrueX and IDVx ads, one for each way ads are inserted:

ExampleAd sourceAd break behavior
CSAI without RAFA VAST/VMAP response parsed by the appThe app schedules and plays the ad pod itself
RAF CSAIA VMAP parsed by the Roku Advertising Framework (RAF)RAF parses the response and plays the regular ads
Google IMA DAIA Google DAI streamGoogle DAI returns one stream with stitched ad breaks

Each example has its own player, ad, and TruexAdRenderer code on purpose, so you can pick the one closest to your setup and read it from top to bottom. All three load the library the same way - see SDK Integration.

Running the Apps ​

Requirements:

  • A Roku device in developer mode
  • The app source from the repository below, sideloaded to the device

Test IP parameter

The TrueX ad server serves ads in the US and Canada only. If your team or CI runs outside those regions, ask your Infillion contact for the test ip parameter to add to the sample VAST tags. Do not use it in production.

Shared Rules ​

All three examples follow the same rules, implemented as small functions you can copy:

  • An ad is an Infillion ad if its <AdSystem> is trueX or IDVx, compared case-insensitively.
  • TrueX is interactive only as the first ad in the pod; at a later position it plays as a regular linear ad. IDVx is interactive in any position.
  • adParameters comes from the ad (see Resolving adParameters). If it is missing or invalid, the renderer is not started and the pod continues.
  • Only a TrueX ad that fired adFreePod skips the rest of the pod after adCompleted.
  • userCancelStream closes the player screen.

CSAI without RAF ​

Repository: truex-roku-csai-reference-app

The app parses the VAST itself and plays the ad pod with its own player, without the Roku Advertising Framework.

  1. Load the library - main-scene.xml declares the ComponentLibrary and main-scene.brs waits for loadStatus to be ready.
  2. Detect the ad - playback-screen.brs checks the <AdSystem> value of each ad in the pod.
  3. Resolve adParameters - the generic <AdParameters> JSON, or the base64 companion payload.
  4. Start the renderer - it creates TruexLibrary:TruexAdRenderer, sends init and start, and handles the events in onTruexEvent.
  5. Continue the pod - after the terminal event, the app discards the rest of the pod after a TrueX adFreePod, or starts the next ad in the pod.

RAF CSAI ​

Repository: truex-roku-raf-csai-reference-app

RAF parses the ad response, finds the ads, and plays the regular ads. The app only takes over for the Infillion ad.

  1. Set up RAF - PlaybackTask.brs gives RAF the ad URL (a VMAP with TrueX ads in a preroll and a midroll pod).
  2. Detect the ad - handleAdPod() reads the pod with Roku_Ads().getAds() and classifies each ad.
  3. Play the Infillion ad - playTrueXAd() creates the renderer in the ad container passed by the flow, resolves adParameters from the ad's adParameters or companionAds, and waits for the terminal event.
  4. Play the rest of the pod - if the user did not earn the reward, Roku_Ads().showAds() plays the remaining ads. RAF owns the thread until the ads finish, so the app restores the content position afterwards.

Google IMA DAI ​

Repository: truex-roku-google-ad-manager-reference-app

The Google IMA SDK for Roku plays a DAI stream with the ads stitched into it. The integration is in ImaSdkTask.brs and ContentFlow.brs, and the code is marked with numbered comments that match the steps in the repository README:

  1. Keep track of the current ad break - save the break in the IMA adBreakStarted callback.
  2. Look for the Infillion companion - in onStreamStarted, inspect the ad's companions for apiFramework truex.
  3. Parse adParameters - decode the base64 companion payload into JSON.
  4. Prepare to enter the ad - pause the stream and seek over the placeholder ad.
  5. Initialize and start the renderer - send init, wait for adFetchCompleted, and send start.
  6. Respond to adFreePod - seek the stream over the current ad break.
  7. Respond to the terminal events - resume playback after adCompleted, adError, or noAdsAvailable.
  8. Respond to userCancelStream - leave the stream.

Integration documentation for Infillion Ads