处理播放多个m3u8类型的视频(mp4可直接播放)

2021-10-29  本文已影响0人  Limolovely

代码:

$(function() {

if (Hls.isSupported()) {

var videoList = document.getElementsByTagName('video');

for (var i = 0; i < videoList.length; i++) {

if (videoList[i]) {

var videoSrc = $(videoList[i]).attr("src")

var index = videoSrc.lastIndexOf(".");

var type = videoSrc.substring(index + 1);

if (type == "m3u8") {

var hls = new Hls();

hls.loadSource(videoSrc);

hls.attachMedia(videoList[i]);

hls.on(Hls.Events.MANIFEST_PARSED, function() {

videoList[i].play();

});

}

}

}

}

});

需要引用的js+Q:392415576,也可自行下载

上一篇下一篇

猜你喜欢

热点阅读