Hi, I am trying to figure out how to make mp3 music start when I click my channel and have it stop when I select a Category and video when I hit Play. I use the videoplayer from the sdk
I need to be able to do this using an external xml file as I do for my video content now to change at will my mp3 selection at the start of the Channel.
It’s working now
I have a function call appSound(screen) in appMain.brs and a stopSound in videoplayer.brs that works now. I just need a way to get an xml file read in to play the mp3 versus placing the http path to the mp3 in the appSound.brs.
Here is my appSound.brs content. I am still new at programming so be easy on me and if you have a complete solution let me know or PM me.
Function startSound(screen)
m.audio = CreateObject("roAudioPlayer")
item = CreateObject("roAssociativeArray")
item.Url = "http://www.xxxxx.org/roku/music/Letsride.mp3"
item.StreamFormat = "mp3"
m.audio.AddContent(item)
item.Url = "http://www.xxxxx.com/RokuDir/audio/town.mp3"
item.StreamFormat = "mp3"
m.audio.AddContent(item)
m.audio.SetLoop(true)
m.audio.Play()
' you can add more audio as this has 2 mp3's in line to play or add more.
End Function
Function stopSound()
m.audio.Stop()
End Function
It wouldn’t have to be XML simply to play a music file. You could use GetToString() and then use a single line txt file with the http path for the mp3.
MP3TextTransfer=CreateObject(“roUrlTransfer”)
MP3TextTransfer.SetUrl(“http path to text file http://myserver.com/mp3filename.txt”)
MP3Filename=MP3TextTransfer.GetToString()
For multiple files if needed, a playlist like you have playing two, you could use Tokenize to break the string into a multiple part array based on a character in the string.
GetToString is faster than running an entire xml parsing routine when dealing with a tiny/limited data set.
I am missing something here and just get errors at line 7. Ahhhh. Here is what I tried. My item.Url variable is the path to my text file and inside the file is the http link to the actual mp3 file.
Function startSound(screen)
m.audio = CreateObject("roAudioPlayer")
item = CreateObject("roAssociativeArray")
item.TextTransfer=CreateObject("roUrlTransfer")
item.Url = "http://www.xxxxx.org/roku/mp3filename.txt"
MP3Filename=TextTransfer.GetToString()
item.StreamFormat = "mp3"
m.audio.AddContent(MP3Filename)
print item
print MP3Filename
m.audio.SetLoop(true)
m.audio.Play()
End Function
Function stopSound()
m.audio.Stop()
End Function
Tried it that way and no response. How strange as my print item shows the correct path to the mp3 file itself. I will pm you the full path in the file.
I think you need to wait on the roAudioPlayer events in order for you to hear the audio.
This code should play your mp3 file through to the end. You can modify it as necessary to keep playing until stopSound() is called.
Function startSound(screen)
TextTransfer=CreateObject("roUrlTransfer")
TextTransfer.SetUrl("http://www.xxxxx.org/roku/mp3filename.txt")
MP3Filename=TextTransfer.GetToString()
m.audio = CreateObject("roAudioPlayer")
port=CreateObject("roMessagePort")
m.audio.SetMessagePort(port)
item = CreateObject("roAssociativeArray")
item.Url=MP3Filename
item.StreamFormat = "mp3"
m.audio.AddContent(item)
m.audio.SetLoop(False)
m.audio.Play()
While True
msg = Wait (0, port)
If Type (msg) = "roAudioPlayerEvent"
If msg.IsRequestSucceeded() or msg.IsRequestFailed () or msg.IsFullResult () or msg.IsPartialResult () or msg.IsRequestInterrupted ()
Exit While
EndIf
EndIf
End While
End Function