From 251a601da70b38c22b8d2198d670acb0601cba02 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Thu, 14 Sep 2023 00:14:10 +0300 Subject: [PATCH] Extract HLS stream test function --- src/plugins/htmlVideoPlayer/plugin.js | 9 ++++----- src/utils/mediaSource.ts | 10 ++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/utils/mediaSource.ts diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 9a928709ac32..e26569bb0dd0 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -35,6 +35,7 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../components/ba import { PluginType } from '../../types/plugin.ts'; import Events from '../../utils/events.ts'; import { includesAny } from '../../utils/container.ts'; +import { isHls } from '../../utils/mediaSource.ts'; import debounce from 'lodash-es/debounce'; /** @@ -74,7 +75,7 @@ function enableNativeTrackSupport(mediaSource, track) { return true; } - if (browser.firefox && (mediaSource?.TranscodingSubProtocol || mediaSource?.Container) === 'hls') { + if (browser.firefox && isHls(mediaSource)) { return false; } @@ -344,12 +345,10 @@ export class HtmlVideoPlayer { const mediaSource = streamInfo.mediaSource; const item = streamInfo.item; - const isHls = (mediaSource?.TranscodingSubProtocol || mediaSource?.Container) === 'hls'; - // Huge hack alert. Safari doesn't seem to like if the segments aren't available right away when playback starts // This will start the transcoding process before actually feeding the video url into the player // Edit: Also seeing stalls from hls.js - if (mediaSource && item && !mediaSource.RunTimeTicks && isHls && streamInfo.playMethod === 'Transcode' && (browser.iOS || browser.osx)) { + if (mediaSource && item && !mediaSource.RunTimeTicks && isHls(mediaSource) && streamInfo.playMethod === 'Transcode' && (browser.iOS || browser.osx)) { const hlsPlaylistUrl = streamInfo.url.replace('master.m3u8', 'live.m3u8'); loading.show(); @@ -513,7 +512,7 @@ export class HtmlVideoPlayer { elem.crossOrigin = crossOrigin; } - if (enableHlsJsPlayer(options.mediaSource.RunTimeTicks, 'Video') && (options.mediaSource.TranscodingSubProtocol || options.mediaSource.Container) === 'hls') { + if (enableHlsJsPlayer(options.mediaSource.RunTimeTicks, 'Video') && isHls(options.mediaSource)) { return this.setSrcWithHlsJs(elem, options, val); } else if (options.playMethod !== 'Transcode' && options.mediaSource.Container === 'flv') { return this.setSrcWithFlvJs(elem, options, val); diff --git a/src/utils/mediaSource.ts b/src/utils/mediaSource.ts new file mode 100644 index 000000000000..e4af1f3f1983 --- /dev/null +++ b/src/utils/mediaSource.ts @@ -0,0 +1,10 @@ +import { MediaSourceInfo } from '@jellyfin/sdk/lib/generated-client'; + +/** + * Checks if the media source is an HLS stream. + * @param mediaSource The media source. + * @returns _true_ if the media source is an HLS stream, _false_ otherwise. + */ +export function isHls(mediaSource: MediaSourceInfo|null|undefined): boolean { + return (mediaSource?.TranscodingSubProtocol || mediaSource?.Container) === 'hls'; +}