2017-04-06 85 views
0

是否有一种简单的方法来检查HLS(M3U8)流是否可用,如果不是,则显示错误消息?我正在使用以下代码播放M3U8流,但如果流不可用,则“正在检索”消息只会显示无限期的时间。检查HLS流是否已启动并显示错误消息(如果不是)?

我想显示错误立即如果流不起来。

sub onButtonSelected() 
    'Ok' 
    if m.ButtonGroup.buttonSelected = 0 
    m.Video.visible = "true" 
    m.Video.control = "play" 
    m.Video.setFocus(true) 
    'Add error message logic here if stream doesn't play 

    'Exit button pressed' 
    else 
    m.Exiter.control = "RUN" 
    end if 
end sub 

回答

0

您应该观察视频播放器的状态。

sub onButtonSelected() 
    'Ok' 
    if m.ButtonGroup.buttonSelected = 0 
    m.Video.visible = "true" 
    ' This observer should not be set here because it will add new observer every time you 
    ' select the button. For demonstration purposes only. 
    m.video.observeField("state", "onVideoStateChanged") 
    m.Video.control = "play" 
    m.Video.setFocus(true) 

    'Exit button pressed' 
    else 
    m.Exiter.control = "RUN" 
    end if 
end sub 


sub onVideoStateChanged(event as Object) 
    if event.getData() = "error" 
     ' Show error dialog here 
    end if 
end sub 

您也可以通过检查ERRORMSG/的errorCode视频节点的领域看到错误消息/码。

相关问题