Forum Discussion

mahamudm's avatar
mahamudm
Visitor
14 years ago

videoplayer not supporting both hls(live) and mp4(vod)

I am using the videoplayer example to have channels that are live (hls) and Video on Demand(MP4). I can have only one of them at a time but not both with this example since I had to modify the code to play one format. Is there an example that allows a mix of live and VOD channels ? or can I modify the videoplayer code below to support both? need help since i am not familiar with the roku brightscript syntax.

1. Edit appMain.brs and change the line
videoclip.StreamFormat = "mp4"
to
videoclip.StreamFormat = "hls"


once I do that change it only allows hls and vice versa.

please help.

6 Replies

  • destruk's avatar
    destruk
    Streaming Star
    If you obtain the type specifier from the url filename, then it can be a bit more dynamic for you.
    ie
    videoclip.streamformat=right(episode.streamurl,3)
    You don't even have to change any xml for that. In order to work, the streamformat needs to be set after the streamurl has been.
  • "destruk" wrote:
    If you obtain the type specifier from the url filename, then it can be a bit more dynamic for you.
    ie
    videoclip.streamformat=right(episode.streamurl,3)
    You don't even have to change any xml for that. In order to work, the streamformat needs to be set after the streamurl has been.


    Except that the HLS file extension is .m3u8 so that logic would get you a streamFormat = "3u8". And if the stream URL has any parameters on it, the result becomes unpredictable. The videoplayer example has support for specifying the streamFormat in the XML starting on line 142 of showFeed.brs.
  • destruk's avatar
    destruk
    Streaming Star
    So if it's "3u8" then you have your code change it to m3u8, and if there are parameters, do a string comparison for a ? since that's the first character for any further parameters.
    Or, like you said, just change the xml file it parses - but what if you don't have access or permissions to change the xml file, then how do you do it?
  • "destruk" wrote:
    So if it's "3u8" then you have your code change it to m3u8, and if there are parameters, do a string comparison for a ? since that's the first character for any further parameters.
    Or, like you said, just change the xml file it parses - but what if you don't have access or permissions to change the xml file, then how do you do it?


    You could do a HEAD request and check the content-type header
  • Thanks for your help, i need help with the head request code, in rbightscript, how would do a head request cto change the content type ?


    Also for unknown reason line # 142 function call for validstr(curShow.streamFormat.GetText()) always returns empty value. I do have a value for the streamFormat in my xml ( see listed below code snipet from creativity). but if i manually set to one type e.g. hls or mp4 then it works for me but i want dynamic setting not hardcoding. your help is really appreciated. thanks in advance.

    inside the showfeed.brs file, line #142
    'fetch all values from the xml for the current show
    item.hdImg = validstr(curShow@hdImg)
    item.sdImg = validstr(curShow@sdImg)
    item.ContentId = validstr(curShow.contentId.GetText())
    item.Title = validstr(curShow.title.GetText())
    item.Description = validstr(curShow.description.GetText())
    item.ContentType = validstr(curShow.contentType.GetText())
    item.ContentQuality = validstr(curShow.contentQuality.GetText())
    item.Synopsis = validstr(curShow.synopsis.GetText())
    item.Genre = validstr(curShow.genres.GetText())
    item.Runtime = validstr(curShow.runtime.GetText())
    item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
    item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
    item.StreamFormat = validstr(curShow.streamFormat.GetText())
    if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
    item.StreamFormat = "mp4"
    endif

    END OF SAMPLE CODE

    Creativity.xml

    Creativity.xml CODE:

    <item sdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/ElizabethGilbert.jpg" hdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/ElizabethGilbert.jpg">
    <title>Elizabeth Gilbert on nurturing creativity</title>
    <contentId>10051</contentId>
    <contentType>Talk</contentType>
    <contentQuality>SD</contentQuality>
    <streamFormat>hls</streamFormat>
    <media>
    <streamQuality>SD</streamQuality>
    <streamBitrate>1500</streamBitrate>
    <streamUrl>http://video.ted.com/talks/podcast/ElizabethGilbert_2009_480.m3u8</streamUrl>
    </media>
    <synopsis>Elizabeth Gilbert</synopsis>
    <genres>Creativity</genres>
    <runtime>1172</runtime>
    </item>
    <item sdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/SethGodin.jpg" hdImg="http://rokudev.roku.com/rokudev/examples/videoplayer/images/SethGodin.jpg">
    <title>Seth Godin on standing out</title>
    <contentId>10052</contentId>
    <contentType>Talk</contentType>
    <contentQuality>SD</contentQuality>
    <streamFormat>mp4</streamFormat>
    <media>
    <streamQuality>SD</streamQuality>
    <streamBitrate>1500</streamBitrate>
    <streamUrl>http://video.ted.com/talks/podcast/SethGodin_2003_480.mp4</streamUrl>
    </media>
    <synopsis>In a world</synopsis>
    <genres>Creativity</genres>
    <runtime>1024</runtime>
    </item>