### Fast Start Media Playback Configuration (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/core-concepts/playing-videos.md Configures the Video node to prebuffer media for a faster start. This is achieved by setting the 'control' field to 'prebuffer' while the user is viewing media details, and then to 'start' upon user selection for playback. ```BrightScript sub setDetailsScreenFocus() if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.videoPlayer.hasFocus() then m.buttons.setFocus(true) ' prebuffer video while user is reading the details screen m.videoPlayer.control = "prebuffer" end if end sub m.videoPlayer.control = "start" ``` -------------------------------- ### Install Roku Robot Framework Library (Python) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/automated-testing-overview.md Installs the Roku Robot Framework Library locally using pip. This allows direct import into Robot test case files. Ensure you have Python and pip installed. ```python pip install /automated-channel-testing-master/RobotLibrary ``` -------------------------------- ### Initialize Roku Ads Library and Get Ads Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/advertising/integrating-roku-advertising-framework.md This snippet demonstrates the initial setup for the Roku Ads library. It includes including the library, constructing the interface, setting a custom ad URL, and fetching ad pods. Error checking and object validity checks are omitted for brevity. ```BrightScript Library "Roku_Ads.brs" adIface = Roku_Ads() adIface.setAdUrl(myAdUrl) adPods = adIface.getAds() ``` -------------------------------- ### License Period Start Example (XML) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/trc-docs/video-on-demand/delivery/ingest-specifications.md Example for setting the start date of content availability. The date must follow ISO 8601 format (YYYY-MM-DDTHH:MM:SS) and be chronologically before the end date. It is optional. ```xml YYYY-MM-DDTHH:MM:SS ``` -------------------------------- ### Example Robot Framework Multi-Device Configuration Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/automated-testing-overview.md An example of a populated config.json file for multi-device testing. It includes specific device names, IP addresses, timeouts, press delays, server path, test file, and output directory. ```json { "devices": { "Amarillo": { "ip_address": "192.168.1.64", "timeout": 20000, "pressDelay": 2000 }, "Littlefield": { "ip_address": 192.168.1.16, "timeout": 25000, "pressDelay": 1000 } }, "server_path": "/automated-channel-testing-master/bin/RokuWebDriver_", "test": "Tests/Basic_tests_multi_device.robot", "outputdir": "Results" } ``` -------------------------------- ### GET /v1/session/:sessionId/apps Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/web-driver.md Retrieves a list of all apps currently installed on the device. ```APIDOC ## GET /v1/session/:sessionId/apps ### Description Retrieves a list of apps currently installed on the device. ### Method GET ### Endpoint /v1/session/:sessionId/apps ### Response #### Success Response (200) - **sessionId** (string) - The advertising ID of the device. - **status** (int) - A status code summarizing the result of the command. - **value** (array) - An array of installed apps. - **Title** (string) - The title of the app. - **ID** (string) - The ID of the app. - **Version** (string) - The build version of the app. - **Subtype** (string) - The subtype of the app ("ndka"/"rsga"). - **Type** (string) - The type of the app ("menu"/"appl"). #### Response Example ```json { "sessionId": "some-session-id", "status": 0, "value": [ { "Title": "Example App", "ID": "com.example.app", "Version": "1.0.0", "Subtype": "rsga", "Type": "appl" } ] } ``` ``` -------------------------------- ### Initialize and Run a SceneGraph Application Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifsgscreen.md Demonstrates the initialization of an roSGScreen, setting up a message port, creating a SceneGraph scene, and entering a message loop to handle screen events. This example requires a 'TrivialScene' to be defined elsewhere. ```BrightScript sub showChannelSGScreen() print "in showChannelSGScreen" screen = CreateObject("roSGScreen") m.port = CreateObject("roMessagePort") screen.setMessagePort(m.port) m.global = screen.getGlobalNode() m.global.id = "GlobalNode" m.global.addFields( {red: &hff0000ff, green: &h00ff00ff, blue: &h0000ffff} ) scene = screen.CreateScene("TrivialScene") screen.show() scene.setFocus(true) child = createObject("RoSGNode","ContentNode") child.contentkey = "test_string" print "child: '"; child.contentkey; "'" while(true) msg = wait(0, m.port) msgType = type(msg) if msgType = "roSGScreenEvent" if msg.isScreenClosed() then return end if end while end sub ``` -------------------------------- ### GET Request to File Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifurltransfer.md Starts a GET request without waiting for completion. The response body is written to a specified file on the device's filesystem. ```APIDOC ## AsyncGetToFile ### Description Starts a transfer without waiting for it to complete, similar to the [AsyncGetToString()](https://developer.roku.com/en-gb/docs/references/brightscript/interfaces/ifurltransfer.md#asyncgettostring-as-boolean) method. However, the response body will be written to a file on the device's filesystem instead of being returned in a String object. When the GET request completes, an [roUrlEvent](https://developer.roku.com/docs/references/brightscript/events/rourlevent.md "roUrlEvent") will be sent to the message port associated with the object. If false is returned then the request could not be issued and no events will be delivered. ### Method BrightScript Function (Implied) ### Endpoint N/A (Method on an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```brightscript ' Assuming 'transfer' is an instance of roUrlTransfer success = transfer.AsyncGetToFile("roku_data.txt") if not success then print "Request could not be issued." end if ``` ### Response #### Success Response An [roUrlEvent](https://developer.roku.com/docs/references/brightscript/events/rourlevent.md "roUrlEvent") is sent upon completion. #### Response Example N/A (Event-driven) #### Parameters - **filename** (String) - Required - The file on the Roku device's filesystem to which the response body is to be written ``` -------------------------------- ### Initialize Item Poster and Content Display in BrightScript Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/core-concepts/controlling-screen-program-flow.md Initializes the item poster node and sets up the content display by updating the URI for the item icon, the text for the item label, and the URI for the HD poster. ```brightscript sub init() m.itemposter = m.top.findNode("itemPoster") end sub sub showcontent() itemcontent = m.top.itemContent m.itemicon.uri = itemcontent.url m.itemlabel.text = itemcontent.title m.itemposter.uri = itemcontent.HDPosterUrl end sub ``` -------------------------------- ### Get Installed Apps Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/javascript-library.md Returns a list of all installed applications on the device, including details like title, ID, type, version, and subtype. ```APIDOC ## GET /getApps ### Description Returns a list of installed apps as an array of objects. Each app object contains the following fields: title, id, type, version, and subtype. ### Method GET ### Endpoint /getApps ### Parameters None ### Request Example ```bash const apps = await library.getApps() ``` ### Response #### Success Response (200) - **apps** (array) - An array of app objects. - **title** (string) - The title of the app. - **id** (string) - The unique identifier of the app. - **type** (string) - The type of the app. - **version** (string) - The version of the app. - **subtype** (string) - The subtype of the app. #### Response Example ```json [ { "title": "Example App", "id": "some_id", "type": "app", "version": "1.0.0", "subtype": "" } ] ``` ``` -------------------------------- ### BrightScript Identifier Examples Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/language/expressions-variables-types.md Examples of valid BrightScript identifiers, demonstrating the rules for starting characters, allowed characters, and optional type designators for variables. ```brightscript a boy5 super_man$ ``` -------------------------------- ### Request User Data for Sign-up (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/scenegraph/control-nodes/channelstore.md Demonstrates requesting multiple user data properties for a sign-up process. It shows how to set the requestedUserData field and then access the retrieved user information after the command is executed. ```BrightScript store = CreateObject("roSGNode", "ChannelStore") ' Request several properties for sign-up store.requestedUserData = "email, phone, firstname, lastname" store.command = "getUserData" ' Store requested properties email = store.userdata.email firstname = m.store.userData.firstname lastname = m.store.userData.lastname phone = m.store.userData.phone ``` -------------------------------- ### Get Installed Roku Apps Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/javascript-library.md Retrieves a list of all installed applications on the Roku device. Returns an array of app objects, each containing details like title, id, type, version, and subtype. Used for verifying app installations and properties. ```javascript const apps = await library.getApps() expect(apps[0].ID).to.equal('some_id') ``` -------------------------------- ### Signal EPG Launch Beacons in BrightScript Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifsgnodefield.md This example shows how to fire both the initiation and completion beacons for the Electronic Program Grid (EPG) launch. `EPGLaunchInitiate` is called when the EPG display begins, and `EPGLaunchComplete` is called when the EPG is fully rendered and operational. Only the first sequence of EPG launch beacons is recorded. ```brightscript myEPGComponent.signalBeacon("EPGLaunchInitiate") m.top.signalBeacon("EPGLaunchComplete") ``` -------------------------------- ### License Period End Example (XML) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/trc-docs/video-on-demand/delivery/ingest-specifications.md Example for setting the end date of content availability. The date must conform to ISO 8601 format (YYYY-MM-DDTHH:MM:SS) and be chronologically after the start date. It is optional. ```xml YYYY-MM-DDTHH:MM:SS ``` -------------------------------- ### Initialize ChannelStore API and Observe Request Status (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/roku-pay/implementation/tvod-app-catalog.md Initializes the ChannelStore API by finding the 'channelStore' node and setting up an observer for the 'requestStatus' field. The onRequestStatus callback function is triggered on changes, parsing the command and status to direct results to specific handlers. ```BrightScript function init() m.store = m.parent.FindNode("channelStore") m.store.observeField("requestStatus", "onRequestStatus") end function ' Generic SDK API request callback function onRequestStatus() requestStatus = m.store.requestStatus if requestStatus = Invalid print "Invalid requestStatus" else print "requestStatus", requestStatus print "requestStatus.command", requestStatus.command print "requestStatus.status", requestStatus.status print "requestStatus.statusMessage", requestStatus.statusMessage print "requestStatus.context", requestStatus.context ' requestStatus.status: ' 2: Interrupted ' 1: Success ' 0: Network error ' -1: HTTP Error/Timeout ' -2: Timeout ' -3: Unknown error ' -4: Invalid request ' Generic request succeeded if requestStatus.status = 1 then if requestStatus.command = "DoOrder" then onOrderStatus(requestStatus.result) end if end if end if end function ``` -------------------------------- ### Schedule Object Example Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/trc-docs/live-linear/ovp-linear-ingest-spec.md An example of a Schedule object, used for live feeds. It includes program ID, duration, live status, date, start times, and optional attributes like Closed Captions (CC). ```json { "id": "programId", "isLive": false, "date": "2020-01-13", "times": [ "21:30" ], "durationInSeconds": 2760, "attributes": [ "CC" ] } ``` -------------------------------- ### Extract Mid Substring (Start Index Only) (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifstringops.md Returns all characters from the roString object starting at a specified zero-based index to the end of the string. This is useful for getting the remainder of a string from a certain point. ```brightscript myString = "BrightScript" remaining = myString.Mid(6) print remaining ' Output: Script ``` -------------------------------- ### Initialize roInput and Message Port for Voice Commands Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/media-playback/voice-controls/transport-controls.md This snippet demonstrates the initial setup for handling voice commands. It involves creating an roInput object and an roMessagePort to receive events, then associating them by calling SetMessagePort. ```BrightScript input = CreateObject("roInput") port = CreateObject("roMessagePort") input.SetMessagePort(port) ``` -------------------------------- ### Timer Control Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/robot-framework-library.md Keywords for managing a timer. 'Mark timer' starts the timer, and 'Get timer' returns the elapsed milliseconds since the timer was last started. Available since release 2.0. ```BrightScript Mark timer ${time} = Get timer ``` -------------------------------- ### BrightScript: Initialize roChannelStore and Set Order Action Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/roku-pay/implementation/on-device-upgrade-downgrade.md Initializes the roChannelStore object and sets the action for a plan transaction (Upgrade or Downgrade). The action is case-sensitive and must be 'Upgrade' or 'Downgrade'. ```BrightScript m.store = CreateObject("roChannelStore")​ ' Populate myOrderItems myOrderInfo.action = "Upgrade" ``` -------------------------------- ### Get List of Installed Roku Apps Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/robot-framework-library.md Keyword to retrieve a list of all installed applications on the Roku device. Returns an array of objects, each containing details like title, ID, type, version, and subtype. ```robotframework @{apps}=Get Apps ``` -------------------------------- ### Execute Order and Check Status using BrightScript Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/roku-pay/quickstart/add-ons-integration.md This function sends the `DoOrder` command to purchase a base product and any associated add-ons. It constructs an `orderItems` array and sends it as part of the request. The `onOrderStatus` function handles the response, including success messages and detailed purchase information. ```BrightScript sub DoOrder() request = {} request.command = "DoOrder" orderItems = [] if m.content.base <> "" then orderItems.push({ "sku" : m.content.base "qty" : 1 }) end if for each addon in m.content.addons orderItems.push({ "sku" : addon "qty" : 1 }) end for request.params = { "version": 2 "orderItems": orderItems } m.store.request = request end sub function onOrderStatus(requestResult as object) as void print chr(10) + "onOrderStatus" dialog = CreateObject("roSGNode", "statusDialog") message = "" if requestResult.status <> 1 message = "status: " + str(requestResult.status) + chr(10) message += "statusMessage: " + requestResult.statusMessage else message = "Your Purchase completed successfully" + chr(10) message += "statusMessage: " + requestResult.statusMessage + chr(10) if type(requestResult.result) = "roAssociativeArray" then purchases = requestResult.result.purchases ' roArray if type(purchases) = "roArray" then for i = 0 to purchases.Count() - 1 message += chr(10) + "Product " + AnyToString(i+1) + ":" + chr(10) item = purchases[i] ' roAssociativeArray print type(item) print "item", item if item.replacedPurchase <> invalid then print "item.replacedPurchase", item.replacedPurchase end if keys = item.Keys() for each key in keys strField = AnyToString(item[key]) if strField <> Invalid if strField.len() > 0 message += key + " = " + strField + chr(10) else message += key + " = " + chr(10) end if else message += key + " = " + chr(10) end if end for end for end if end if end if print "message", message dialog.message = message m.top.getScene().dialog = dialog end function ``` -------------------------------- ### MPEG-4 Video Playback Setup (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/core-concepts/playing-videos.md Sets up playback for MPEG-4 video files. It involves configuring the ContentNode with the 'mp4' stream format and the video file's URL. ```BrightScript videoContent = createObject("RoSGNode", "ContentNode") videoContent.url = "video_URI" videoContent.streamformat = "mp4" ``` -------------------------------- ### Get Timer Elapsed Time Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/javascript-library.md Retrieves the number of milliseconds that have elapsed since the timer was last started. ```APIDOC ## GET /getTimer ### Description Returns the number of milliseconds elapsed since the timer was last started. Available since release 2.0. ### Method GET ### Endpoint /getTimer ### Parameters None ### Request Example ```bash let time = library.getTimer(); ``` ### Response #### Success Response (200) - **elapsedTime** (number) - The number of milliseconds elapsed since the timer was started. #### Response Example ```json { "elapsedTime": 14000 } ``` ``` -------------------------------- ### ParallelAnimation Node Example in BrightScript Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/scenegraph/animation-nodes/parallelanimation.md This example demonstrates how to use the ParallelAnimation node in BrightScript to animate multiple elements simultaneously. It defines several child Animation nodes, each interpolating different fields (scale and opacity) of Rectangle components. The script initializes the animation by setting its repeat property to 'true' and control to 'start'. ```xml ``` -------------------------------- ### Configure Stream Start Time Offset and Format Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/getting-started/architecture/content-metadata.md Sets an optional offset into the stream for the playback start position in seconds, and specifies the content type format. ```brightscript StreamStartTimeOffset: 3600 StreamFormat: "hls" ``` -------------------------------- ### Format Date as String - roDateTime Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/components/rodatetime.md Shows how to get the current date from a roDateTime object and format it as a string using the AsDateString method. The 'long-date' format is used in this example. ```BrightScript date = CreateObject("roDateTime") print "The date is now "; date.AsDateString("long-date") ``` -------------------------------- ### Encrypt and Decrypt Example Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifdevicecrypto.md Example demonstrating the usage of Encrypt() and Decrypt() methods to encrypt and then decode plaintext on a Roku device. ```APIDOC ## Example Usage ### Description This example demonstrates how to encrypt plaintext on a Roku device and then decode it using the `ifDeviceCrypto` interface. ### Code Snippet ```brightscript ' store plaintext to be encrypted in an roByteArray ba = CreateObject("roByteArray") ba.FromAsciiString("plain text1") ' create roDeviceCrypto object and specify a device key dc = CreateObject("roDeviceCrypto") encType = "device" ' encrypt plaintext using the device key and store the encoded data in an roByteArray encrypted = dc.Encrypt(ba, encType) ' decode the encrypted data and store the decrypted data in an roByteArray if encrypted <> invalid then decrypted = dc.Decrypt(encrypted, encType) end if ' The 'decrypted' variable now holds the original plaintext as an roByteArray. ``` ``` -------------------------------- ### Get Signed Long from Byte Array (BrightScript) Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/brightscript/interfaces/ifbytearray.md Retrieves a signed long (four bytes) from the Byte Array, starting at a specified zero-based index. This is useful for reading multi-byte integer values. ```brightscript function GetSignedLong(index as Integer) as Integer ' Returns the signed long (four bytes) starting at the specified zero-based index in the Byte Array. end function ``` -------------------------------- ### Create Pre-built Dialog and Handle Button Events in BrightScript Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/references/scenegraph/standard-dialog-framework-nodes/standard-dialog-framework-overview.md Demonstrates how to instantiate a StandardMessageDialog, set its properties (title, message, buttons), observe the 'buttonSelected' field for event handling, and display the dialog. It also includes the callback function to process button selections. ```BrightScript sub showAccountDialog() ' set up the dialog m.accountDialog = createObject("roNode", "StandardMessageDialog") m.accountDialog.title = "Let's create your account!" m.accountDialog.message = [ "Sign up for a free account to start streaming today." ] m.accountDialog.buttons = [ "Continue", "Cancel" ] ' observe the dialog's buttonSelected field to handle button selections m.accountDialog.observeFieldScoped("buttonSelected", "onButtonSelected") ' display the dialog scene.dialog = m.accountDialog end sub 'detect button events sub onButtonSelected() ' use the dialogs buttonSelected field to perform the appropriate action if m.accountDialog.buttonSelected = 0 doContinueAction() else if m.accountDialog.buttonSelected = 1 doCancelAction() end if end sub ``` -------------------------------- ### Get Elapsed Time from Timer Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/javascript-library.md Returns the number of milliseconds that have elapsed since the timer was last started using `markTimer`. Useful for verifying operation durations. Available since release 2.0. ```javascript let time = library.getTimer(); expect(14000).greaterThan(time); ``` -------------------------------- ### Sequential Ad Pod Rendering Example Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/advertising/integrating-roku-advertising-framework.md This example illustrates sequential ad pod rendering within the content video event loop. It uses `getAds()` as an event listener to determine when scheduled ad breaks should occur. The code handles stopping content playback, rendering the ad pod, and resuming playback. ```BrightScript shouldPlayContent = adIface.showAds(adPods) while shouldPlayContent videoMsg = wait(0, contentVideoScreen.GetMessagePort()) adPods = adIface.getAds(videoMsg) if adPods <> invalid and adPods.Count() > 0 contentVideoScreen.Close() ' stop playback of content shouldPlayContent = adIface.showAds(adPods) ' render current ad pod if shouldPlayContent ' *** Insert client app’s resume-playback code here end if end if ' *** Insert client app’s video event handler code here end while ``` -------------------------------- ### Get Specific Element Source: https://github.com/robsonharrison/brightscriptdocsscraper/blob/main/docs/docs/developer-program/dev-tools/automated-channel-testing/robot-framework-library.md Searches for and returns information about the first element matching the specified locator, starting from the screen root. Supports element and parent locators, along with a delay for retries. ```BrightScript ***Variables*** &{ElementData}= using=text value=some text @{ElementArray}= &{ElementData} &{ElementParams} elementData=${ElementArray} ***Test Cases*** &{element}= Get element ${ElementParams} ```