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">
  <interface>
    <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" />
  </interface>
  <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" />
</component>

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="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<!-- importing main handler -->
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
<children>
    <MMTask id="MM"/>
</children>

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 support@mediamelon.com

'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=m.top.FindNode("MM")
m.MM.setField("video", m.video)
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.setFocus(true)
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 ‘contentNode.live’ has to be set to true as shown below:

  contentNode.live= 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 : m.video.errorMsg }

Step 5: CSAI Ad Tracking using Roku Ad FrameWork

    RAF = Roku_Ads()
    RAF.setAdUrl(vastTag)

    logObj = {
        log: function(evtType = invalid as dynamic, ctx = invalid as dynamic)
            'The below function sends the Ad data to MediaMelon SDK for ad tracking
            sendAdDataToMMSDK(ctx)
    }
    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 m.global <> invalid and m.global.MMAnalytics <> invalid
        m.global.MMAnalytics.setField("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"
        m.top.playingAd = true
        print "Preroll adPods > " adPods
        m.global.MMAnalytics.setField("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
        m.global.MMAnalytics.setField("mmAdPlaying", true) 'This line is part of MM SDK Integration
        video.control = "stop"
 end if

Last updated