Plug-in record-dplayer live plug-in

"dplayer": "^1.26.0", 

The use record of the live broadcast plug-in supports live broadcast or playback video playback in m3u8 format. It has good compatibility with ios and Android. iOS does not support automatic playback.

import flvjs from 'flv.js';
<div id="dplayer"></div>
// 直播
    initFlv () {
      let Hls = require('hls.js');
      let DPlayer = require('dplayer');
      let _this = this;
      let jsonobj = JSON.stringify;
      console.log(jsonobj);
      const dp = new DPlayer({
        container: document.getElementById('dplayer'),
        live: true,
        video: {
          url: this.liveInfo.live_url,
          type: 'customHls',
          pic: this.liveInfo.pic_url,
          customType: {
            customHls: function (video, player) {
              hls.loadSource(video.src);
              hls.attachMedia(video);
            }
          }
        }
      });
      dp.play();
      dp.on('canplay', function () {
        console.log('player good');
        _this.canplay = true;
      });
      dp.on('loadedmetadata', function () {
        console.log('player loadedmetadata');
        _this.canplay = true;
      });
      // 直播等待中,重新获取直播
      dp.on('waiting', function () {
        _this.waitTime = +_this.waitTime + 10;
        setTimeout(res => {
          console.log(_this.canplay);
          if (_this.waitTime < 60 && !_this.canplay) {
            _this.initFlv();
          }
        }, 10000);
        console.log(_this.waitTime);
      });
    },
 "dplayer": "^1.26.0",

Guess you like

Origin blog.csdn.net/qq_38068508/article/details/125727900