在 Roku Brighscript 中:如果/当 HSL 流停止播放时如何刷新视频场景?

问题描述 投票:0回答:1

我有这个非常简单的 roku 应用程序,通过这个单一视频场景可以永远播放实时 m3u8 流。但最终视频冻结了。是否可以检测视频未播放、销毁并重新创建视频内容?

<?xml version = "1.0" encoding = "utf-8" ?> 
<component name = "VideoExample" extends = "Scene" >
  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
      videocontent = createObject("RoSGNode", "ContentNode")
      videocontent.live = true
      videocontent.PlayStart = 999999999
      videocontent.streamformat = "hls"
      videocontent.url = "my_m3u8_url"

      video = m.top.findNode("exampleVideo")
      video.content = videocontent

      video.setFocus(true)
      video.control = "play"
    end sub

    ]]>

  </script>
  <children >
    <Video id = "exampleVideo"/>
  </children>
</component>
roku brightscript
1个回答
0
投票

要跟踪视频的状态并检测视频是否冻结,您可以使用

observeField
来监视视频节点的
state
字段。如果视频状态指示错误或停止播放,您可以使用新内容重新启动播放器。这是代码的更新版本,进行了必要的更改:

<?xml version = "1.0" encoding = "utf-8" ?> 
<component name = "VideoExample" extends = "Scene" >
  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
        videocontent = createObject("RoSGNode", "ContentNode")
        videocontent.live = true
        videocontent.PlayStart = 999999999
        videocontent.streamformat = "hls"
        videocontent.url = "my_m3u8_url"
      
        video = m.top.findNode("exampleVideo")
        video.observeField("state", "onStateChanged")
        video.content = videocontent

        video.setFocus(true)
        video.control = "play"
    end sub

    sub onStateChanged(event as object)
        state = event.getData()
      
        ? "onStateChanged(), state = " state
      
        if (state = "error" or state = "finished")
          restartPlayer()
        end if
      
    end sub
      
    sub restartPlayer()
       ' logic to restart the player with new content
    end sub

    ]]>

  </script>
  <children >
    <Video id = "exampleVideo"/>
  </children>
</component>

请检查视频节点文档,了解有关

state
字段及其可能值的更多详细信息。 此外,您可以查看 observeField 文档 了解更多信息。

关于冻结问题本身,一个可能的根本原因可能是视频流过期。所以,您可能也想检查一下。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.