首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未指定或无效的曲目路径/ Livestream.com流的url- Roku

未指定或无效的曲目路径/ Livestream.com流的url- Roku
EN

Stack Overflow用户
提问于 2015-07-09 04:38:36
回答 1查看 2.5K关注 0票数 0

我正在开发一个自定义的Roku频道,我需要使用来自以下直播流事件的livestream.com视频流:

http://livestream.com/accounts/11222132/events/3665575

使用他们的json服务,我已经能够获得一个m3u8流。这个流在iOS、安卓和Fire OS上运行良好,但我不能让它在Roku上运行。

下面的代码获取并尝试播放我的流:

代码语言:javascript
复制
Function displayVideo()
    print "Displaying video: "
    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

    'bitrates  = [0]          ' 0 = no dots, adaptive bitrate
    'bitrates  = [348]    ' <500 Kbps = 1 dot
    'bitrates  = [664]    ' <800 Kbps = 2 dots
    'bitrates  = [996]    ' <1.1Mbps  = 3 dots
    'bitrates  = [2048]    ' >=1.1Mbps = 4 dots
    bitrates  = [0]    


    request = CreateObject("roUrlTransfer")
    request.SetUrl("http://livestream.com/api/accounts/11222132/events/3665575/viewing_info")
    jsonString = request.GetToString()
    myJson = ParseJSON(jsonString)
    theurl = myJson.streamInfo.m3u8_url
    urls = [theurl]
    print "the json url is:"
    print urls
    qualities = ["SD"]
    StreamFormat = "hls"
    title = "COACB TV 39"
    srt=""

    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = bitrates
    videoclip.StreamUrls = urls
    videoclip.StreamQualities = qualities
    videoclip.StreamFormat = streamformat
    videoclip.Title = title
    print "srt = ";srt
    if srt <> invalid and srt <> "" then
        videoclip.SubtitleUrl = srt
    end if



    video.SetContent(videoclip)
    video.show()

    lastSavedPos   = 0
    statusInterval = 10 'position must change by more than this number of seconds before saving

    while true
        msg = wait(0, video.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000

                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
End Function

在我的控制台中,我得到了以下相关消息:

显示视频:

json url是:

http://api.new.livestream.com/accounts/11222132/events/3665575/broadcasts/92495453.m3u8?dw=100&hdnea=st=1436386598~exp=1436387498~acl=/i/11222132_3665575_bee34040_1@123585/*~hmac=dfacbbb090cc8df9435397d7c38d134be418756b3a00620297948eea35bedae7

srt =

未知事件: 11消息:未指定或无效的曲目路径/url。

播放失败:

关闭视频屏幕

我得到的这个错误表明这个url是无效的,事实上,如果我给它一个url值“什么都没有,亲爱的”,它也会给我同样的错误。所以如果我从这个json得到的url是错误的..那这有什么错呢?它能在我的其他设备上工作。

EN

回答 1

Stack Overflow用户

发布于 2015-07-09 09:20:49

从一系列互联网面包屑中,我发现了以下urls的答案:

首先,这个人有和我一样的问题:

http://forums.roku.com/viewtopic.php?f=34&t=83773&p=494689&hilit=livestream.com#p494689

他说他在这里找到了解决方案:http://forums.roku.com/viewtopic.php?f=34&t=66537&p=425668&hilit=akamai

第二个链接没有对我的问题有一个完整的解决方案,但它只缺少一些我已经添加到解决方案中的东西,我将在下面发布。如果你想把一个json直播流放到roku应用程序中,你需要使用他们的应用程序接口来获取一个包含m3u8流的livestream.com对象。通常情况下,你只需将这个url发送到视频播放器,它就可以工作,但它需要2个cookie,它不会自动获得。在这种情况下,我们必须提取它们,然后将它们重新附加到另一个请求。

代码语言:javascript
复制
'*************************************************************
'** displayLivestream()
'*************************************************************
Function displayLivestream ()
    request = CreateObject("roUrlTransfer")
    request.SetUrl("http://livestream.com/api/accounts/11222132/events/3665575/viewing_info")
    jsonString = request.GetToString()
    myJson = ParseJSON(jsonString)
    theurl = myJson.streamInfo.m3u8_url
   print theurl


   req = CreateObject("roUrlTransfer")
   req.SetPort(CreateObject("roMessagePort"))
   req.SetUrl(theurl)   
   req.EnableCookies()
   req.EnableFreshConnection(true)   
   if (req.AsyncGetToString())
      event = wait(30000, req.GetPort())
      if type(event) = "roUrlEvent"
         if (event.GetResponseCode() <> 200)
            'DisplayDialog("No Live Feed", "Please check back later.")
            print "roUrlEvent"
         endif

         headers = event.GetResponseHeadersArray()
      else if event = invalid
          print "AsyncGetToString timeout"
          req.AsyncCancel()
      else
          print "AsyncGetToString unknown event"
      endif
   endif


   Location = ""
   for each header in headers
      print header
      val = header.LookupCI("Set-Cookie")
      val2 = header.LookupCI("Location")
      if (val <> invalid)
         if (val.Left(5) = "hdntl")
            hdntl = val.Left(Instr(1,val,";")-1)
         endif
         if (val.Left(6) = "_alid_")
            alid = val.Left(Instr(1,val,";")-1)
         endif
      endif
      if (val2 <> invalid)
        Location = val2
      endif
   end for

   port = CreateObject("roMessagePort")
   screen = CreateObject("roVideoScreen")
   screen.SetMessagePort(port)
   screen.EnableCookies()  
   print "hdntl is:" 
   print hdntl
   print "alid is:" alid
   screen.AddHeader("Cookie",hdntl)
   screen.AddHeader("Cookie", alid)
   stream = {
      HDBranded: false
      IsHD: false
      StreamBitrates: [0]
      StreamUrls: [theurl]
      StreamQualities: [0]
      StreamFormat: "hls"
      Live: true
   }

   screen.SetContent(stream)
   screen.Show()
   lastSavedPos   = 0
   statusInterval = 10 'position must change by more than this number of seconds before saving

    while true
        msg = wait(0, screen.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000

                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31303240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档