android h5 hls,uni-app video标签打包H5Android上支持播放.m3u8 hls直播流

默认uni-app打包出来的H5在Android上是没法播放.m3u8直播流的,控制台或报错Uncaught (in promise) DOMException: The element has no supported sources.

可以用hls.js来解决,在App.vue的onLaunch方法中增加加下列代码即可:// 下面的代码增加对Android H5播放m3u8支持

// #ifdef H5

if (uni.getSystemInfoSync().platform != 'ios') {

var script = document.createElement("script");

script.src = "https://cdn.jsdelivr.net/npm/hls.js@latest";

script.onload = function() {

let init = function(video) {

if (!video.getAttribute('hls-inited')) {

let hls = null;

let load = function() {

let src = video.src;

if (!src || src.indexOf('.m3u8') < 0)

return

if (!hls) {

hls = new Hls();

hls.attachMedia(video);

}

hls.loadSource(src);

}

你可能感兴趣的:(android,h5,hls)