Roku Player

This document describes the Roku MediaMelon Player SDK Integration with the Roku media player.

This document describes the Roku MediaMelon Player SDK Integration with the Roku media player.

Step 1: Add the MediaMelon Player SDK

Unzip the MediaMelon Player SDK and place its contents in the MMSmartStream Folder in the components directory of the sample application code downloaded from the link above.

Step 2: Setup a new MediaMelon Player SDK Task

Create a new Task XML named MMTask.xml inside your components folder and give it the following interface. This is used to link the SmartSight Player SDK's Brightscript files into your application.

The MMTask.xml file should contain the following code:

<component name="MMTask" extends="Task">
    <field id="video" type="node" alwaysNotify="true"/>
    <field id="config" type="assocarray" alwaysNotify="true"/>
    <field id="customTags" type="assocarray" alwaysNotify="true"/>
    <field id="contentMetadata" type="assocarray" alwaysNotify="true"/>
    <field id="error" type="assocarray" alwaysNotify="true"/>
    <field id="view" type="String" alwaysNotify="true"/>
    <field id="exit" type="Boolean" alwaysNotify="true"/>
    <field id="sdk_version" type="String" alwaysNotify="true"/>
    <field id="mmAdData" type="assocarray" alwaysNotify="true" />
    <field id="mmAdPlaying" type="Boolean" alwaysNotify="true" />
  <script type="text/brightscript" uri="pkg:/components/MMSmartStream/MMSmartStreamWrapper.brs" />
  <script type="text/brightscript" uri="pkg:/components/MMSmartStream/MMSmartStreamEngine.brs" />
  <script type="text/brightscript" uri="pkg:/components//MMSmartStream/MMSmartStreamRokuPlugin.brs" />
  <script type="text/brightscript" uri="pkg:/components/MMSmartStream/Utilities.brs" />

Step 3: Integrate MediaMelon Player SDK Code to the Main Application

Add a child component to the main video scenecustom-playback-channel-master/components/MainScene.xml

<component name="MainScene" extends="Scene" xmlns:xsi="" xsi:noNamespaceSchemaLocation="">
<!-- importing main handler -->
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
    <MMTask id="MM"/>

Within the main application, after the video instance has been created, create the SmartSight Player SDK Task node, and pass the Video node to it.

Note: <customer_id> is your MediaMelon-assigned Customer ID. If you do not know your Customer ID contact MediaMelon at

'Mandatory fields are customerID and subscriberId.'
MMConfig = {
  customerID : "CUSTOMER_ID"
  subscriberId : "SUBSCRIBER_ID"
  subscriberType: "SUBSCRIBER_TYPE"
  subscriberTag: "SUBSCRIBER_TAG"
  playerName: "PLAYER_NAME"
  disableManifestFetch: false
  domainName: "DOMAIN_NAME"
  appName: "APP_NAME"
  appSdkVersion: "APP_VERSION"
m.MM.setField("config", MMConfig)

contentMetadata = {
    "assetName": "ASSET_NAME",
    "assetId": "ASSET_ID",
    "videoId": "VIDEO_ID",
    "contentType": "CONTENT_TYPE",
    "genre": "GENRE",
    "drmProtection": "DRM_PROTECTION",
    "episodeNumber": "EPISODE_NUMBER",
    "season": "SEASON",
    "seriesTitle": "SERIES_TITLE",
    "videoType": "VIDEO_TYPE"
m.MM.setField("contentMetadata", contentMetadata)

customMetadata = {
    "key1": "VALUE_STRING1",
    "key2": "VALUE_STRING2",
    "key3": "VALUE_STRING3"
m.MM.setField("customTags", customMetadata)

m.MM.control = "RUN"
m.player.observeField("state", "videoStateChange")

Note: There is an upper limit of 3 custom tags that can be sent to SmartSight. If you need to send more tags, please contact your MediaMelon sales representative.

For Live streams ‘’ has to be set to true as shown below: true

Step 4: Error handling

In most cases the Error handling in Roku applications is done by an Error Handler at the application level. For passing on the errors to the Media Melon SDK the following code snippet needs to be added to the error handling function.

 'Send the error message to the MM SDK
 m.MM.error = { errorMsg : }

Step 5: CSAI Ad Tracking using Roku Ad FrameWork

    RAF = Roku_Ads()

    logObj = {
        log: function(evtType = invalid as dynamic, ctx = invalid as dynamic)
            'The below function sends the Ad data to MediaMelon SDK for ad tracking
    logFunc = function(obj = invalid as dynamic, evtType = invalid as dynamic, ctx = invalid as dynamic)
        obj.log(evtType, ctx)
    end function
    RAF.setTrackingCallback(logFunc, logObj)
    adPods = RAF.getAds()
function sendAdDataToMMSDK(ctx as object)
    if <> invalid and <> invalid"mmAdData", ctx)
    end if
end function

Set the field named mmAdPlaying to true when an ad break started as shown below:

'preroll ads
if adPods <> invalid and adPods.count() > 0
        video.control = "stop" = true
        print "Preroll adPods > " adPods"mmAdPlaying", true) 'This line is part of MM SDK Integration
        keepPlaying = RAF.showAds(adPods, invalid, view)
 end if

'midroll ads
 if adPods <> invalid and adPods.count() > 0
        'ask the video to stop - the rest is handled in the state=stopped event below
        print "Midroll adPods > " adPods"mmAdPlaying", true) 'This line is part of MM SDK Integration
        video.control = "stop"
 end if




String containing the Player Name.


String containing your MediaMelon-assigned Customer ID.


String containing your Subscriber’s ID. If you do not use subscriber IDs, enter null


String containing your section of your subscriber or assets. (Optional)


String containing App Name.


String containing App Version


String containing the Subscriber Type (e.g. “Free”, “Paid”). If you do not use subscriber types, enter null


String containing an additional subscriber-specific information. This is sent in clear (not hashed) to SmartSight and it is advised to not send sensitive information in this field.


String containing Asset Id.


String containing Asset Name.


String containing your video’s ID. If you do not use videos IDs, enter null.


String containing type of the Content. For example - "Movie", "Special", "Clip", "Scene Epis Lifts".


String containing Genre of the content. For example - "Comedy", "Horror".


Widevine, Fairplay, Playready etc. Unknown means content is protected, but protection type is unknown. For clear contents, do not set this field


String containing sequence number of the Episode.


String containing the Season. For example - "Season1".


String containing Title of the Series.


String containing Video Type. For example - "LIVE", "VOD".


Extra custom metadata can be added here if required. If extra metadata is not required, enter null.

Last updated