使用 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,视频