If your Xml file has a simple, single-layer structure, like the one in your link, then all you need is a single .brs file.
The easiest way to get it up and running is to take the
customvideoplayer channel and replace the entire contents of main.brs with this code:
sub main ()
xml = readXml ("http://tecmediainc.atspace.co.uk/live_playingnow.xml", 5000)
if xml <> invalid
contentList = getContentList (xml)
displayPoster (contentList)
endif
end sub
function getContentList (xml as object) as object
contentList = []
for each item in xml.item
categoriesList = []
for each genre in item.genres
categoriesList.Push (genre.GetText ())
end for
if item.live.GetText () = "true" then live = true else live = false
contentList.Push ({
ShortDescriptionLine1: item.title.GetText (),
ShortDescriptionLine2: item.synopsis.GetText (),
SDPosterUrl: item@sdImg,
HDPosterUrl: item@hdImg,
Description: item.synopsis.GetText (),
StreamFormat: item.streamFormat.GetText (),
StreamUrls: [item.streamMinUrl.GetText ()],
StreamQualities: [item.streamQuality.GetText ()],
StreamContentIDs: [item.contentId.GetText ()],
StreamBitrates: [0],
Live: live,
Title: item.title.GetText (),
Length: item.runtime.GetText ().ToInt (),
Categories: categoriesList
})
end for
return contentList
end function
sub displayPoster (contentList as object)
port = CreateObject ("roMessagePort")
poster = CreateObject ("roPosterScreen")
poster.SetMessagePort (port)
poster.SetListStyle ("flat-category")
poster.SetBreadcrumbEnabled (true)
poster.SetBreadcrumbText ("tintumonkb's videos", "")
poster.SetContentList (contentList)
poster.SetFocusedListItem (0)
poster.Show ()
while true
msg = Wait (0, port)
if type (msg) = "roPosterScreenEvent"
if msg.IsScreenClosed ()
exit while
else if msg.IsListItemSelected ()
index = displaySpringboard (contentList, msg.GetIndex ())
poster.SetFocusedListItem (index)
endif
endif
end while
end sub
function displaySpringboard (contentList as object, index as integer) as integer
content = contentList [index]
port = CreateObject ("roMessagePort")
screen = CreateObject ("roSpringboardScreen")
screen.SetMessagePort (port)
screen.SetDescriptionStyle ("movies")
screen.SetPosterStyle ("rounded-square-generic")
screen.SetBreadcrumbEnabled (true)
screen.SetBreadcrumbText ("tintumonkb's videos", "")
screen.SetStaticRatingEnabled (false)
screen.AllowNavLeft (true)
screen.AllowNavRight (true)
screen.AddButton (1,"Play Video")
screen.SetContent (content)
screen.Show ()
while true
msg = Wait (0, port)
if type (msg) = "roSpringboardScreenEvent"
if msg.IsScreenClosed ()
exit while
else if msg.IsButtonPressed ()
if msg.GetIndex () = 1 ' Play
displayVideo (content)
endif
else if msg.IsRemoteKeyPressed ()
key = msg.GetIndex ()
if key = 4 ' Back Key - Display previous movie
index = index - 1 : if index < 0 then index = contentList.Count () - 1
content = contentList [index]
screen.SetContent (contentList [index])
screen.Show ()
else if key = 5 ' Forward Key - Display next movie
index = index + 1 : if index >= contentList.Count () then index = 0
content = contentList [index]
screen.SetContent (contentList [index])
screen.Show ()
endif
endif
endif
end while
return index
end function
sub displayVideo (content as object)
port = CreateObject ("roMessagePort")
video = CreateObject ("roVideoScreen")
video.SetMessagePort (port)
video.SetContent (content)
video.Show ()
while true
msg = Wait (0, port)
if type (msg) = "roVideoScreenEvent"
if msg.IsScreenClosed ()
exit while
else if msg.IsPlaybackPosition ()
debug ("isPlayBackPosition")
else if msg.IsRequestFailed ()
debug ("play failed: " + msg.GetMessage () + " Index: " + msg.GetIndex ().ToStr ())
else
debug ("Unknown event: " + msg.GetType ().ToStr () + " msg: " + msg.GetMessage ())
endif
else
debug ("Unknown message type: " + type (msg))
endif
end while
end sub
function readXml (fileName as string, timeout = 0 as integer) as object
xml = Invalid
ut = CreateObject ("roUrlTransfer")
port = CreateObject ("roMessagePort")
ut.SetPort (port)
ut.SetUrl (fileName)
data = ""
if not ut.AsyncGetToString ()
debug ("readXml AsyncGetToString Failed")
else
while true
msg = Wait (timeout, port)
if type (msg) = "Invalid" ' Operation timed out
debug ("readXml Request Timed Out")
ut.AsyncCancel ()
exit while
else if type (msg) = "roUrlEvent"
if msg.GetInt () <> 1
debug ("readXml Request Transfer Did Not Complete")
else
status = msg.GetResponseCode ()
debug ("readXml Request: msg.ResponseCode () = " + status.ToStr () + ". msg.GetFailureReason () = " + msg.GetFailureReason ())
if status <> 200
debug ("readXml Request Did Not Succeed")
else
data = msg.GetString ()
if data = ""
debug ("readXml Request Returned No Data")
else
' We have data
debug ("readXml Response: " + data)
endif
endif
endif
exit while
endif
end while
endif
' Only proceed if data was read
if data <> ""
' Only proceed if the data contains Xml that can be parsed
xml = CreateObject ("roXMLElement")
if not xml.Parse (data)
debug ("readXml Response Parsing Failed")
xml = Invalid
endif
endif
return xml
end function
' In production code, remove the comment from the return statement
sub debug (message as string)
'return
dt = CreateObject ("roDateTime")
dt.Mark ()
dt.ToLocalTime ()
hh = Right ("0" + dt.GetHours ().ToStr (), 2)
mm = Right ("0" + dt.GetMinutes ().ToStr (), 2)
ss = Right ("0" + dt.GetSeconds ().ToStr (), 2)
mmm = Right ("00" + dt.GetMilliseconds ().ToStr (), 3)
print hh + ":" + mm + ":" + ss + "." mmm + " " + message
end sub
Note that you have 4 stream Urls in your Xml, each specifying a different HLS stream. You can only specify a single stream for HLS. I just picked one at random. The m3u8 file you specify should contain a list of streams of varying bitrates.