使用 VideoJS 或类似工具播放 IPTV 直播电视流
我正在尝试使用 videojs 播放直播电视频道。我尝试了各种方法,但总是得到“找不到该媒体的兼容源”。错误。其他视频播放正常。
该 URL 在 VLC 中播放正常,编解码器将流显示为“MPEG-H Part2/HEVC (H.265) (hevc)”。
我也尝试过多种浏览器,chrome、firefox、safari 和 Edge。
这是代码的骨架。有办法玩吗?
<link href="https://vjs.zencdn.net/7.17.0/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-dash/dist/videojs-dash.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
<video id='live-video' class='video-js vjs-default-skin' controls>
</video>
<script>
var player = videojs('live-video');
player.src({ src:'https://www.example.com/play.php?OTUxE2NDUN', type:'application/x-mpegurl'});
player.play();
</script>
I'm trying to play live tv channel with videojs. I've tried various ways but always get "No compatible source was found for this media." error. Other videos are playing fine.
The url plays fine in VLC and the codec shows the stream as "MPEG-H Part2/HEVC (H.265) (hevc)".
I've tried across a range of browsers too, chrome, firefox, safari and edge.
This is the bones of the code. Is there a way to play it ?
<link href="https://vjs.zencdn.net/7.17.0/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
<script src="https://unpkg.com/videojs-contrib-dash/dist/videojs-dash.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
<video id='live-video' class='video-js vjs-default-skin' controls>
</video>
<script>
var player = videojs('live-video');
player.src({ src:'https://www.example.com/play.php?OTUxE2NDUN', type:'application/x-mpegurl'});
player.play();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我得出的结论是,您在基本帖子(问题)中显示的编码没有任何问题。我推测您使用的实际源 URL 不是有效的 HLS 流,因此是您所述错误的原因。
(这可能是一个有效的 DASH 流,但我相当确定
你的代码不能与 DASH 流一起工作。)
这是一些与你的代码等效的工作代码,除了它
使用 Video.js 实时教程中提到的较新(推荐)UI / API。
下面的代码起作用的关键在于它确实引用了有效的 HLS 流...(我在互联网上偶然发现的 URL)。
I've concluded there is nothing wrong with the coding you show in your base posting (question). I speculate that the ACTUAL source URL you were using is NOT a valid HLS stream, and hence the cause of your stated error.
(It's possible that it is a valid DASH stream, but I'm reasonably certain
your code would NOT work with a DASH stream.)
Here's is some working code that is equivalent to yours, except that it
uses the newer (recommended) UI / API, mentioned in the Video.js live tutorial.
The key to WHY the code below works is simply that it DOES reference a valid HLS stream...(a URL that I stumbled upon, on the Internet).
这是在网页中播放流视频的更简单的方法。您可以通过添加 video.js 网站指南中的参数和代码来根据自己的喜好对其进行自定义。
Here is a simpler method of playing streaming video in your webpage. You can customize it to your liking by adding parameters and code from the video.js website guide.