天天看点

VUE中集成H5直播点播播放器LivePlayer过程

基于VUE和webpck的前端工程

1、安装@liveqing/liveplayer

npm -i @liveqing/liveplayer --save-dev      

2、webpack.config.js 添加配置

....
const CopyWebpackPlugin = require('copy-webpack-plugin');
....
   plugins: [
   ...
      new CopyWebpackPlugin([
        { from: 'node_modules/@liveqing/liveplayer/dist/component/crossdomain.xml'},
        { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf'},
        { from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/'}
    ]),
   ...
   ]      

3、配置template.html

<!DOCTYPE HTML>
<html>
    <head>
     .....
        <!--这里的路径是上一步copy,相对于www目录的相对路径,最终目的让浏览器可以访问到这个js-->
        <script src="js/liveplayer-lib.min.js"></script>
    </head>
    <bodyr>
        .....
    </body>
</html>      

4、.vue中使用liveplayer

4.1、 import 引入

import LivePlayer from "@liveqing/liveplayer";      

4.2、 components 中添加

components: {
    LivePlayer
 }      

4.3 页面中添加组件

<div>
   ....
   <LivePlayer :videoUrl="url" live muted stretch></LivePlayer>
   ....
   </div>      

4.4 url设置

this.url = 播放的视频地址      

继续阅读