Videojs - 流未运行时隐藏错误

Tyl*_*rch 4 nginx live-streaming http-live-streaming video.js hls.js

我已经设置了 videojs 播放器,并获得了一个 HLS 流,可以通过 OBS 传输到播放器。当 OBS 运行并将视频发送到流时,播放按钮会出现在播放器上,看起来很正常,但是当没有任何内容流式传输到页面时,它会显示“无法加载媒体,因为服务器或网络出现故障”或者因为格式不受支持。” 其下方的十字错误。这对我来说不是问题,但该页面将被其他人使用,我不想重复自己该网页没有损坏,只是因为它目前没有流式传输。

有没有办法隐藏错误或更改错误上的文本以通知流当前未运行。还有一种方法可以让它在流打开时自动播放。这是我当前的文件,非常基本,只是当前的播放器。

    <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4     <meta charset=utf-8 />
  5     <title>Video.js | HTML5 Video Player</title>
  6     <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
  7 </head>
  8 <body>
  9
 10   <video-js id="example_video_1" class="vjs-default-skin" controls preload="auto" width="640" height="264">
 11     <source src="http://localhost/live/webcam/index.m3u8" type="application/x-mpegurl">
 12     <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <    a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
 13   </video-js>
 14
 15   <script src="https://unpkg.com/video.js/dist/video.js"></script>
 16   <script src="https://unpkg.com/@videojs/http-streaming/dist/videojs-http-streaming.js"></script>
 17
 18   <script>
 19           var player = videojs('example_video_1', {liveui: true});
 20   </script>
 21 </body>
 22
 23 </html>
Run Code Online (Sandbox Code Playgroud)

Pau*_*uda 6

根据您想要执行的操作,您可以调用player.error()null告诉 Video.js 隐藏错误:player.error(null)。如果您只想禁用错误,您可以在播放器选项中设置errorDisplay选项:false

var player = videojs('vid', {
  errorDisplay: false
});
Run Code Online (Sandbox Code Playgroud)

希望有帮助。