Videojs - 当流未运行时隐藏错误

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

我已经设置了 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>
nginx http-live-streaming video.js live-streaming hls.js
2个回答
6
投票

根据您想要执行的操作,您可以使用

player.error()
调用
null
来告诉 Video.js 隐藏错误:
player.error(null)
。 如果您只想禁用错误,您可以在播放器选项中将
errorDisplay
选项设置为
false

var player = videojs('vid', {
  errorDisplay: false
});

希望有帮助。


0
投票

我不明白这个。

player.error
下来不以
null
为参数,只以
string | number | MediaError | undefined
为参数。在选项中添加
errorDisplay: false
也没有任何区别。还有其他人让它工作吗?

© www.soinside.com 2019 - 2024. All rights reserved.