0
点赞
收藏
分享

微信扫一扫

ionic3 m3u8在线播放工具,在线播放

金刚豆 2022-04-29 阅读 52

使用 npm:

npm install dplayer --save

npm install hls.js --save

加载播放器文件:

<div id="dplayer"></div>

ts

import DPlayer from 'dplayer/dist/DPlayer.min.js';
import Hls from 'hls.js/dist/hls.min.js';


ionViewDidLoad(){
   this.urlAddress=this.navParams.data.url;
   const dp = new DPlayer({
    container: document.getElementById('dplayer'),
    live: true,  //直播,如果不要直播改为false
    autoplay: true,
    screenshot: true,
    //danmaku: true,
    video: {
url:'http://hls.cntv.lxdns.com/asp/hls/main/0303000a/3/default/978a64ddd3a1caa85ae70a23414e6540/main.m3u8',
        type: 'customHls',
        customType: {
            customHls: function (video, player) {
                const hls = new Hls();
                hls.loadSource(video.src);
                hls.attachMedia(video);
            },
        },
    },
});
}

完成,即可播放m3u8,视频 

举报

相关推荐

0 条评论