How To Play Audio In Roku

Posted By : Deepak Gupta | 08-Aug-2014

 

In previous blog I have discussed that how we can create channel in Roku.  Now we are going to learn how to play audio in it.

 

port = CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")
audio = CreateObject("roAudioPlayer")
screen.SetMessagePort(port)
audio.SetMessagePort(port)
song = CreateObject("roAssociativeArray")
song.url = "http://ia700601.us.archive.org/10/items/HindiPravachanMp3-ByShriShankaracharyaJi/12-SIDE-A.mp3"
song.streamformat="mp3"
bitrates  = [10240]
song.StreamBitrates=bitrates
screen.AddButton(1,"Play")
screen.AddButton(2,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.UseStableFocus(true)
audio.addContent(song)
audio.setloop(false)
screen.Show()
while true
        msg = wait(20000, screen.GetMessagePort())
        if type(msg) = "roSpringboardScreenEvent"
       if msg.isScreenClosed() then             
            exit while               
            else if msg.isButtonPressed()
       if msg.GetIndex() = 1
            audio.Play()
            end if
            endif
    end while

 

 

First of we create a spring board object that display the audio file in rectangle box like UI.This object display the information about individual content.

 

Second we create an object of audio player ,this object provides the ability to play audio stream .Mainly it support wma or mp3 file.


Third we create an object of message to get the that are used to get the action on current screen I have set the screen object on audio and rospringboard object to get action perform on the screen.


Then we create an array of associativeArray It is an array of array In this object we have set some parameter audio play and I have pass this as parameter in audio function called addContent.


Then we call the function play() of audio after pressing play button on springboardScreen event.

 

Thanks

Deepak Gupta

 

About Author

Author Image
Deepak Gupta

Deepak is a bright Groovy and Grails developer

Request for Proposal

Name is required

Comment is required

Sending message..