videojs能播放mp4,不能播放rtmp流的问题解决
最近给了一个小任务是要验证下videojs播放rtmp流的问题。
我先是在 http://www.jq22.com/jquery-info404 《视频播放插件Video.js》下载了
根据它提供的demo修改代码如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Video.js 5.18.4</title> <link href="css/video-js.css" rel="stylesheet"> <!-- If youd like to support IE8 --> <script src="js/videojs-ie8.min.js"></script> <style> body{background-color: #191919} .m{ width: 640px; height: 264; margin-left: auto; margin-right: auto; margin-top: 100px; } </style> </head> <body> <div class="m"> <video id="my-video" class="video-js" controls preload="auto" width="640" height="264" poster="MY_VIDEO_POSTER.jpg" data-setup="{}"> <source src="rtmp://live.hkstv.hk.lxdns.com/live/hks" type="rtmp/flv"/> <p class="vjs-no-js"> To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> </p> </video> <script src="http://vjs.zencdn.net/5.18.4/video.min.js"></script> <script type="text/javascript"> var myPlayer = videojs(my-video); videojs("my-video").ready(function(){ var myPlayer = this; myPlayer.play(); }); </script> </div> </body> </html>
运行发现无法成功播放,之前用它的demo播放mp4文件是可以的,排除了代码问题、路径问题、浏览器不支持问题、flash问题(这些问题大家自行百度),后来发现是因为:video.js不支持在本地html页面里播放
于是根据这篇文章:https://blog..net/u011456337/article/details/50704331
《3分钟快速搭建nodejs本地服务器运行测试html/js》 感谢“罗星星的博客”的帮助。
搭建了本地服务器,成功实现了videojs播放rtmp流
问题解决!
另外,我之前下的是下面这个版本:
这个版本就算按照上面的操作了也不能播放,是因为(V6.X.X的都播不了rtmp,V5.x.x的才行,对比发现,V6.X.X目录下没有video-js.swf,rtmp需要flash来播)
具体看:
本人近期专注写论文,没有再弄这个方面的东西了
附上本文文件下载: