美文网首页
video.js 播放M3U8视屏

video.js 播放M3U8视屏

作者: 回忆不死我们不散 | 来源:发表于2019-11-11 10:13 被阅读0次

    首先,我们需要在vue工程中安装video.js相关依赖。

    npm install --save video.js
    npm install --save videojs-contrib-hls
    npm install --save videojs-flash
    

    接着,我们在需要播放视频的页面引入js对象

    import videojs from  'video.js/dist/video.min'
      import 'video.js/dist/video-js.min.css'
      import 'videojs-flash/dist/videojs-flash';
    

    指定一个video容器,例如

    
    <video id="my-video" class="video-js vjs-default-skin" controls preload="auto" poster="../assets/video.png">
        <source src="http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8" type="application/x-mpegURL">
    </video>
    

    最后,我们在mounted节点初始化播放器:

    videojs('my-video', {
        bigPlayButton: false,
        textTrackDisplay: false,
        posterImage: true,
        errorDisplay: false,
        controlBar: true
    }, function () {
        this.play()
    })
    

    多视频列表循环播放代码

    <div v-for="(item,index) in vedioData" :key="'spqymain'+index">
           
            <video :id="'my-video'+index" class="video-js vjs-default-skin  vjs-big-play-centered" controls preload="auto" style='width: 100%;height: 100%'>
        <source :src="item.path" style='width: 100%;height: 100%' type="application/x-mpegURL">
            </video>
          </div>
    
    
    export default {
      data() {
        return {
          vedioData: [
            {
              region: "烟台市蓬莱阁景区1",
              path:
                "http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8",
              type: "application/x-mpegURL" //播放hls流
            },
             {
              region: "烟台市蓬莱阁景区2",
              path:
                "http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8",
              type: "application/x-mpegURL" //播放hls流
            },
          ]
        };
      },
    mounted() {
    //id必须是唯一的,遍历id,
        for(let i=0;i<this.vedioData.length;i++){
          videojs(
          "my-video"+i,
          {
            // bigPlayButton: false,
            textTrackDisplay: false,
            posterImage: true,
            errorDisplay: false,
            controlBar: true
          },
          function() {
            this.play();
          }
        );
        }
        
      },
    }
    

    转载自:https://blog.csdn.net/xingchen678/article/details/100900846

    相关文章

      网友评论

          本文标题:video.js 播放M3U8视屏

          本文链接:https://www.haomeiwen.com/subject/oknzbctx.html