Fix HLS detection

This commit is contained in:
Dmitry Lyzo 2023-08-27 01:33:35 +03:00
parent 171c381768
commit b2c7d93498

View file

@ -69,12 +69,12 @@ function tryRemoveElement(elem) {
} }
} }
function enableNativeTrackSupport(currentSrc, track) { function enableNativeTrackSupport(mediaSource, track) {
if (track?.DeliveryMethod === 'Embed') { if (track?.DeliveryMethod === 'Embed') {
return true; return true;
} }
if (browser.firefox && (currentSrc || '').toLowerCase().includes('.m3u8')) { if (browser.firefox && (mediaSource?.TranscodingSubProtocol || mediaSource?.Container) === 'hls') {
return false; return false;
} }
@ -341,11 +341,11 @@ export class HtmlVideoPlayer {
* @private * @private
*/ */
updateVideoUrl(streamInfo) { updateVideoUrl(streamInfo) {
const isHls = streamInfo.url.toLowerCase().includes('.m3u8');
const mediaSource = streamInfo.mediaSource; const mediaSource = streamInfo.mediaSource;
const item = streamInfo.item; 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 // 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 // This will start the transcoding process before actually feeding the video url into the player
// Edit: Also seeing stalls from hls.js // Edit: Also seeing stalls from hls.js
@ -513,7 +513,7 @@ export class HtmlVideoPlayer {
elem.crossOrigin = crossOrigin; elem.crossOrigin = crossOrigin;
} }
if (enableHlsJsPlayer(options.mediaSource.RunTimeTicks, 'Video') && val.includes('.m3u8')) { if (enableHlsJsPlayer(options.mediaSource.RunTimeTicks, 'Video') && (options.mediaSource.TranscodingSubProtocol || options.mediaSource.Container) === 'hls') {
return this.setSrcWithHlsJs(elem, options, val); return this.setSrcWithHlsJs(elem, options, val);
} else if (options.playMethod !== 'Transcode' && options.mediaSource.Container === 'flv') { } else if (options.playMethod !== 'Transcode' && options.mediaSource.Container === 'flv') {
return this.setSrcWithFlvJs(elem, options, val); return this.setSrcWithFlvJs(elem, options, val);
@ -1561,7 +1561,7 @@ export class HtmlVideoPlayer {
})[0]; })[0];
this.setTrackForDisplay(this.#mediaElement, track, targetTextTrackIndex); this.setTrackForDisplay(this.#mediaElement, track, targetTextTrackIndex);
if (enableNativeTrackSupport(this.#currentSrc, track)) { if (enableNativeTrackSupport(this._currentPlayOptions?.mediaSource, track)) {
if (streamIndex !== -1) { if (streamIndex !== -1) {
this.setCueAppearance(); this.setCueAppearance();
} }