这次给大家带来使用flv.js与video.js做一个视频直播效果,使用flv.js与video.js做出视频直播效果的注意事项有哪些,下面就是实战案例,一起来看一下。
环境配置
首先运行livego
安装与运行obs
打开设置 配置流服务器
连接成功后livego会有提示
提示载入源
进入nginx下的html目录,新建个index1.html与index2.html
然后运行 nginx (运行前自行修改nginx端口)
2.使用flv.js实现直播播放
之前我写过教程《flv.js简单使用示例》
吧之前的代码稍作修改
代码:
<!doctype html><html><head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>flv.js demo</title>
<style>
.maincontainer { display: block; width: 1024px; margin-left: auto; margin-right: auto;
} .urlinput { display: block; width: 100%; margin-left: auto; margin-right: auto; margin-top: 8px; margin-bottom: 8px;
} .centeredvideo { display: block; width: 100%; height: 576px; margin-left: auto; margin-right: auto; margin-bottom: auto;
} .controls { display: block; width: 100%; text-align: left; margin-left: auto; margin-right: auto;
} </style></head><body>
<div class="maincontainer">
<video id="videoelement" class="centeredvideo" controls autoplay width="1024" height="576">your browser is too old which doesn't support html5 video.</video>
</div>
<br>
<div class="controls">
<!--<button onclick="flv_load()">加载</button>-->
<button onclick="flv_start()">开始</button>
<button onclick="flv_pause()">暂停</button>
<button onclick="flv_destroy()">停止</button>
<input style="width:100px" type="text" name="seekpoint" />
<button onclick="flv_seekto()">跳转</button>
</div>
<script src="./flv.js/flv.min.js"></script>
<script>
var player = document.getelementbyid('videoelement'); if (flvjs.issupported()) { var flvplayer = flvjs.createplayer({ type: 'flv', "islive": true,//<====加个这个
url: 'http://127.0.0.1:7001/live/movie/a.flv',//<==自行修改
});
flvplayer.attachmediaelement(videoelement);
flvplayer.load(); //加载
flv_start();
} function flv_start() {
player.play();
} function flv_pause() {
player.pause();
} function flv_destroy() {
player.pause();
player.unload();
player.detachmediaelement();
player.destroy();
player = null;
} function flv_seekto() {
player.currenttime = parsefloat(document.getelementsbyname('seekpoint')[0].value);
} </script></body></html>
访问http://127.0.0.1/index1.html
如果浏览器开始播放视频那说明你已经成功
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
相关阅读:
如何使用canvas来制作好用的涂鸦画板
如何使用s-xlsx之合并单元格
以上就是使用flv.js与video.js做一个视频直播效果的详细内容。