Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/components/ha-hls-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "lit-element";
import { fireEvent } from "../common/dom/fire_event";
import { nextRender } from "../common/util/render-status";
import { getExternalConfig } from "../external_app/external_config";
import type { HomeAssistant } from "../types";

type HLSModule = typeof import("hls.js");
Expand Down Expand Up @@ -93,34 +94,40 @@ class HaHLSPlayer extends LitElement {
}

private async _getUseExoPlayer(): Promise<boolean> {
return false;
if (!this.hass!.auth.external || !this.allowExoPlayer) {
return false;
}
const externalConfig = await getExternalConfig(this.hass!.auth.external);
return externalConfig && externalConfig.hasExoPlayer;
}

private async _startHls(): Promise<void> {
let hls: any;
const videoEl = this._videoEl;
this._useExoPlayer = await this._getUseExoPlayer();
if (!this._useExoPlayer) {
hls = ((await import(/* webpackChunkName: "hls.js" */ "hls.js")) as any)
.default as HLSModule;
let hlsSupported = hls.isSupported();

if (!hlsSupported) {
hlsSupported =
videoEl.canPlayType("application/vnd.apple.mpegurl") !== "";
}
const url = this.url;
const useExoPlayerPromise = this._getUseExoPlayer();
const masterPlaylistPromise = await fetch(url);

if (!hlsSupported) {
this._videoEl.innerHTML = this.hass.localize(
"ui.components.media-browser.video_not_supported"
);
return;
}
const hls = ((await import(
/* webpackChunkName: "hls.js" */ "hls.js"
)) as any).default as HLSModule;
let hlsSupported = hls.isSupported();
Comment thread
uvjustin marked this conversation as resolved.

if (!hlsSupported) {
hlsSupported =
videoEl.canPlayType("application/vnd.apple.mpegurl") !== "";
}

const url = this.url;
if (!hlsSupported) {
this._videoEl.innerHTML = this.hass.localize(
"ui.components.media-browser.video_not_supported"
);
return;
}

if (this._useExoPlayer) {
this._useExoPlayer = await useExoPlayerPromise;
const hevcRegexp = /CODECS=".*?((hev1)|(hvc1))\..*?"/;
const masterPlaylist = await masterPlaylistPromise.text();
Comment thread
uvjustin marked this conversation as resolved.
Outdated
if (hevcRegexp.test(masterPlaylist) && this._useExoPlayer) {
Comment thread
uvjustin marked this conversation as resolved.
Outdated
this._renderHLSExoPlayer(url);
} else if (hls.isSupported()) {
this._renderHLSPolyfill(videoEl, hls, url);
Expand Down