美文网首页
Vue播放m3u8视频格式,Video.js,

Vue播放m3u8视频格式,Video.js,

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

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

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

    引入js对象

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

    videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入

    <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)

    相关文章

      网友评论

          本文标题:Vue播放m3u8视频格式,Video.js,

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