Prefer native hls support

This commit is contained in:
Bram Kragten 2020-06-10 10:59:23 +02:00
parent 256aec5308
commit 6b2754c4cc

View File

@ -125,19 +125,23 @@ class HaCameraStream extends LitElement {
} }
private async _startHls(): Promise<void> { private async _startHls(): Promise<void> {
// eslint-disable-next-line
const Hls = ((await import(
/* webpackChunkName: "hls.js" */ "hls.js"
)) as any).default as HLSModule;
let hlsSupported = Hls.isSupported();
const videoEl = this._videoEl; const videoEl = this._videoEl;
if (!hlsSupported) { const nativeHlsSupported =
hlsSupported = !!videoEl.canPlayType &&
videoEl.canPlayType("application/vnd.apple.mpegurl") !== ""; (videoEl.canPlayType("application/vnd.apple.mpegURL") !== "" ||
videoEl.canPlayType("audio/mpegurl") !== "");
let hlsSupported = false;
let Hls: HLSModule | undefined;
if (!nativeHlsSupported) {
Hls = ((await import(/* webpackChunkName: "hls.js" */ "hls.js")) as any)
.default as HLSModule;
hlsSupported = Hls.isSupported();
} }
if (!hlsSupported) { if (!nativeHlsSupported && !hlsSupported) {
this._forceMJPEG = this.stateObj!.entity_id; this._forceMJPEG = this.stateObj!.entity_id;
return; return;
} }
@ -148,10 +152,10 @@ class HaCameraStream extends LitElement {
this.stateObj!.entity_id this.stateObj!.entity_id
); );
if (Hls.isSupported()) { if (nativeHlsSupported) {
this._renderHLSPolyfill(videoEl, Hls, url);
} else {
this._renderHLSNative(videoEl, url); this._renderHLSNative(videoEl, url);
} else {
this._renderHLSPolyfill(videoEl, Hls!, url);
} }
return; return;
} catch (err) { } catch (err) {
@ -176,7 +180,11 @@ class HaCameraStream extends LitElement {
Hls: HLSModule, Hls: HLSModule,
url: string url: string
) { ) {
const hls = new Hls(); const hls = new Hls({
liveSyncDurationCount: 3,
liveBackBufferLength: 0,
liveDurationInfinity: true,
});
this._hlsPolyfillInstance = hls; this._hlsPolyfillInstance = hls;
hls.attachMedia(videoEl); hls.attachMedia(videoEl);
hls.on(Hls.Events.MEDIA_ATTACHED, () => { hls.on(Hls.Events.MEDIA_ATTACHED, () => {