Hello, Roku Developer! 👋
Welcome to the Mediastream SDK for Roku, designed to streamline the integration of our powerful features into your applications. This SDK provides access to advanced Mediastream capabilities, allowing you to deliver exceptional multimedia experiences to your users.
- Version: The current version of the SDK is 7.0.1.
To integrate the Mediastream Platform SDK into your Roku project, you need to download the package form the following links:
Latest Version:
https://player.cdn.mdstrm.com/roku_sdk/MediaStreamPlayer.pkgSpecific Version:
https://player.cdn.mdstrm.com/roku_sdk/7.0.1/MediaStreamPlayer.pkgOnce downloaded we need to add it to our project. To do this we need to create a folder called source at the base of our project and inside this folder create a new folder called packageFile and place MediaStreamPlayer.pkg inside it.
Then the sdk must be included to the channel. To do this we need to incorporate the following into your MainScene.xml
<interface>
<field id="msPlayerVideoStatus" type="assocarray" alwaysNotify="true"/>
<field id="msPlayerVideoPosition" type="assocarray" alwaysNotify="true"/>
</interface>
<children>
<Group id="msRokuPlayerContainer"></Group>
</children>Now it's time to initialize the SDK, to do it we need:
- Set
m.SDKPathwith the path of where Mediastream.pkg is located - Create an object of type
MediastreamPlayer - Attach the created object to the
msRokuPlayerContainercontainer - Set the
msPlayerVideoPosition,SDKStatusandmsPlayerVideoStatusobservers with functions that allow us to handle these events.
For example, we create a function initPlayer and set Observers to exemplify:
function initPlayer()
print "MainScene : initPlayer"
m.SDKPath = "pkg:/source/packageFile/MediaStreamPlayer.pkg"
if(m.mediaStreamPlayer <> invalid)
m.msRokuPlayerContainer.removeChild(m.mediaStreamPlayer)
m.mediaStreamPlayer = invalid
end if
m.mediaStreamPlayer = CreateObject("roSGNode", "MediaStreamPlayer")
m.mediaStreamPlayer.id = "mediaStreamPlayer"
m.mediaStreamPlayer.callFunc("initializeSDK", m.SDKPath)
m.msRokuPlayerContainer.appendChild(m.mediaStreamPlayer)
end functionThe MediastreamPlayerConfig class in the Mediastream Android SDK provides a range of properties for tailoring and enhancing your playback experience. Here's an overview of the current properties:
id(String): Video, Audio, Live or Episode ID. You can get it from Mediastream Platform.account(String): Account ID. You can get it from Mediastream Platform.type(MediastreamPlayerConfig.VideoTypes): Video type. Possible values: VOD, LIVE, EPISODE. Tells the player what type of content is going to be played.
adUrl(String): AdURL (e.g., VAST). If not specified, will play ads configured in the Mediastream Platform.accessToken(String): Access token for restricted videos.autoplay(boolean): Autoplay video if true. Default: false.dvr(boolean): Player starts prepared to use DVR. Default: false.windowDVR(int): Window DVR voiced in seconds.appName(string): Very useful to identify traffic in platform analytics. Example: "mediastream-app-tv" or "mediastream-app-mobile".playerId(String): Takes player configuration from platform settings.startAt(Number): Skip or seek at starting, used in keep watching so this starts the video at the same point where the user left it.
You can subscribe to different events with the Mediastream SDK for Roku, for example:
function initPlayer()
print "MainScene : initPlayer"
m.SDKPath = "pkg:/source/packageFile/MediaStreamPlayer.pkg"
if(m.mediaStreamPlayer <> invalid)
m.msRokuPlayerContainer.removeChild(m.mediaStreamPlayer)
m.mediaStreamPlayer = invalid
end if
m.mediaStreamPlayer = CreateObject("roSGNode", "MediaStreamPlayer")
m.mediaStreamPlayer.id = "mediaStreamPlayer"
m.mediaStreamPlayer.callFunc("initializeSDK", m.SDKPath)
m.msRokuPlayerContainer.appendChild(m.mediaStreamPlayer)
m.mediaStreamPlayer.observeField("SDKStatus", "onSDKStatusChanged")
end functionsub setObservers()
m.top.observeField("msPlayerVideoPosition", "onMsPlayerVideoPositionChanged")
m.top.observeField("msPlayerVideoStatus", "onMsPlayerVideoStatusChanged")
end subfunction onMsPlayerVideoStatusChanged(eventData as dynamic)
print "MainScene : onMsPlayerVideoStatusChanged " eventData.getData()
end function
function onMsPlayerVideoPositionChanged(eventData as dynamic)
print "MainScene : onMsPlayerVideoPositionChanged " eventData.getData()
end function
function onSDKStatusChanged(event as Dynamic)
payload = event.getData()
print "MainScene : onSDKStatusChanged : payload : " payload
if payload.status = "Loaded" then m.isSDKLoaded = true
end functionThe Mediastream SDK allows you to listen to various events emitted by the player, providing valuable hooks into the playback lifecycle. Here are the available events:
-
playing:- Called whenever the video starts playing.
-
paused:- Called whenever the video stops playing.
-
finished:- Called whenever the video ends playing.
-
buffering:- Called when player enters buffering state.
These events allow you to respond dynamically to various states and actions during playback.
In the following example, you'll find an application showcasing various uses of the Mediastream SDK for Roku. This app provides practical examples of key functionalities, including audio playback, video playback, audio as a service, casting, and more. Make sure you enter the IDs corresponding to your ACCOUNT_ID and CONTENT_ID and enjoy.
