mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 15:56:35 +00:00
Get regular playlist url properly in ha-hls-player (#7417)
This commit is contained in:
parent
cec2a61bdf
commit
e4ce6117a1
@ -104,7 +104,6 @@ class HaHLSPlayer extends LitElement {
|
|||||||
|
|
||||||
private async _startHls(): Promise<void> {
|
private async _startHls(): Promise<void> {
|
||||||
const videoEl = this._videoEl;
|
const videoEl = this._videoEl;
|
||||||
const playlist_url = this.url.replace("master_playlist", "playlist");
|
|
||||||
const useExoPlayerPromise = this._getUseExoPlayer();
|
const useExoPlayerPromise = this._getUseExoPlayer();
|
||||||
const masterPlaylistPromise = fetch(this.url);
|
const masterPlaylistPromise = fetch(this.url);
|
||||||
|
|
||||||
@ -126,13 +125,30 @@ class HaHLSPlayer extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._useExoPlayer = await useExoPlayerPromise;
|
this._useExoPlayer = await useExoPlayerPromise;
|
||||||
let hevcRegexp: RegExp;
|
const masterPlaylist = await (await masterPlaylistPromise).text();
|
||||||
let masterPlaylist: string;
|
|
||||||
if (this._useExoPlayer) {
|
// Parse playlist assuming it is a master playlist. Match group 1 is whether hevc, match group 2 is regular playlist url
|
||||||
hevcRegexp = /CODECS=".*?((hev1)|(hvc1))\..*?"/;
|
// See https://tools.ietf.org/html/rfc8216 for HLS spec details
|
||||||
masterPlaylist = await (await masterPlaylistPromise).text();
|
const playlistRegexp = /#EXT-X-STREAM-INF:.*?(?:CODECS=".*?(?<isHevc>hev1|hvc1)?\..*?".*?)?(?:\n|\r\n)(?<streamUrl>.+)/g;
|
||||||
|
const match = playlistRegexp.exec(masterPlaylist);
|
||||||
|
const matchTwice = playlistRegexp.exec(masterPlaylist);
|
||||||
|
|
||||||
|
// Get the regular playlist url from the input (master) playlist, falling back to the input playlist if necessary
|
||||||
|
// This avoids the player having to load and parse the master playlist again before loading the regular playlist
|
||||||
|
let playlist_url: string;
|
||||||
|
if (match !== null && matchTwice === null) {
|
||||||
|
// Only send the regular playlist url if we match exactly once
|
||||||
|
playlist_url = new URL(match.groups!.streamUrl, this.url).href;
|
||||||
|
} else {
|
||||||
|
playlist_url = this.url;
|
||||||
}
|
}
|
||||||
if (this._useExoPlayer && hevcRegexp!.test(masterPlaylist!)) {
|
|
||||||
|
// If codec is HEVC and ExoPlayer is supported, use ExoPlayer.
|
||||||
|
if (
|
||||||
|
this._useExoPlayer &&
|
||||||
|
match !== null &&
|
||||||
|
match.groups!.isHevc !== undefined
|
||||||
|
) {
|
||||||
this._renderHLSExoPlayer(playlist_url);
|
this._renderHLSExoPlayer(playlist_url);
|
||||||
} else if (hls.isSupported()) {
|
} else if (hls.isSupported()) {
|
||||||
this._renderHLSPolyfill(videoEl, hls, playlist_url);
|
this._renderHLSPolyfill(videoEl, hls, playlist_url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user