Audio Streaming in Roku

Posted By : Rohit Kaushik | 30-Oct-2014

Every application of ROKU (i.e. written in brightscript) start from main.

 

For playing audio on we have to create a “roSpringboardScreen” object.The SpringboardScreen shows detailed information about an individual piece of content and provides options for actions that may be taken on that content.

First of all we have to initialize values to be set further for your sceenboard .Values like title, desciption, length, content type for audio.We can get all these values from the json also.

 

 


Item = {
    ContentType      :”audio” 
	Title                   :json.video[videoIndex].title 
	SDPosterUrl      :json.video[videoIndex].thumbnailUrl 
	HDPosterUrl     :json.video[videoIndex].thumbnailUrl 
	Description        :json.video[videoIndex].Description 
	StreamUrls        :[json.video[videoIndex].url] 
	Duration            :json.video[videoIndex].Duration 
	Length               :json.video[videoIndex].Duration 
	 }

}

 

Then you have to create object of “roSpringboardScreen” & “roAudioPlayer” and registered it with “roMessagePort”.A Message Port is the place messages (events) are sent.

 

Port = CreateObject(”roMessagePort”)
screen = CreateObject(”roSpringboardScreen”)
audio = CreateObject(”roAudioPlayer”)
screen.SetMessagePort(port)
audio.SetMessagePort(port)

 

Now you have to set all the audio item detail on screen due to which roSpringboardScreen create a screen for audio.Actually roSpringboardScreen create different screen for different content type.We can add buttons to the screen with actions such as Play, Resume, GoBack or moreinfo.When a button is selected then a event occur and we have to handle it.

 

screen.SetContent(item)
screen.AddButton(1,”Play”)
screen.AddButton(2,”Go Back”)
screen.Show()

 

The Audio Player object provides the ability to setup the playing of a series of audio streams. The object accepts an array that describe the audio file url,streamformat & bitrates.The supported streamformat are “mp3”, “wma”, “mp4”, “hls”, “es.aac-adts”, “flac”. Now add all the content on audioplayer.For this we have to create a array and set all the audio content.

 

song=createObject(“roAssociativeArray”)
song.url =  item.StreamUrls[0]
song.streamformat=”hls”
bitrates  = [10240]
song.StreamBitrates=bitrates
audio.addContent(song)

 

Now we want that audio must play if someone press button “Play” ,process waits untill any event occure.For this we have to create a while loop and wait for any event.

 

While true 
msg = wait(0, screen.GetMessagePort()) 
if type(msg) = “roSpringboardScreenEvent”

When event occure on any button then we get the index of that button and perform their operation.

if msg.GetIndex() = 1
audio.Play()

 

means when user press “play” button then we just call the audio.play() function and audio start.

Similary for pause,resume,stop operartions audioplayer provide functions

 

 

About Author

Author Image
Rohit Kaushik

Rohit is a bright IPTV Developer and have worked on various developments.

Request for Proposal

Name is required

Comment is required

Sending message..