From 193c89802e9dd7e663faefd44e168f39ac3053a1 Mon Sep 17 00:00:00 2001 From: gnattu Date: Fri, 26 Apr 2024 06:00:24 +0800 Subject: [PATCH 1/6] Fix MP3 audio playback capability checking with HLS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous check was too naive, assuming that most browsers that support playing MP3 directly in an mp4 file can support MP3 with HLS. However, this assumption is wrong. In fact, most browsers won’t play MP3 with HLS, with Safari being the only exception. Even on Safari, MP3 support with HLS is limited to the mpegts container, and it won’t play MP3 in the fmp4 container. --- src/scripts/browserDeviceProfile.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index 33e07e4f0c..f3908d9999 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -121,6 +121,16 @@ function supportsAc3InHls(videoTestElement) { return false; } +function supportsMp3InHls(videoTestElement) { + + if (videoTestElement.canPlayType) { + return videoTestElement.canPlayType('application/x-mpegurl; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, '') + || videoTestElement.canPlayType('application/vnd.apple.mpegURL; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, ''); + } + + return false; +} + function canPlayAudioFormat(format) { let typeString; @@ -460,6 +470,7 @@ export default function (options) { } const canPlayAacVideoAudio = videoTestElement.canPlayType('video/mp4; codecs="avc1.640029, mp4a.40.2"').replace(/no/, ''); + const canPlayMp3VideoAudioInHls = supportsMp3InHls(videoTestElement); const canPlayAc3VideoAudio = supportsAc3(videoTestElement); const canPlayEac3VideoAudio = supportsEac3(videoTestElement); const canPlayAc3VideoAudioInHls = supportsAc3InHls(videoTestElement); @@ -474,12 +485,16 @@ export default function (options) { if (supportsMp3VideoAudio) { videoAudioCodecs.push('mp3'); + } - // PS4 fails to load HLS with mp3 audio - if (!browser.ps4) { - hlsInTsVideoAudioCodecs.push('mp3'); - } + // Safari is the only browser that supports mp3 with HLS, but only in mpegts container. + // The detect function will return false on Safari, which reflects the fmp4 support, so we have to hard-code it here. + if (browser.safari || canPlayMp3VideoAudioInHls) { + hlsInTsVideoAudioCodecs.push('mp3'); + } + // Most browsers won't support mp3 with HLS, so this is usually false, but just in case. + if (canPlayMp3VideoAudioInHls) { hlsInFmp4VideoAudioCodecs.push('mp3'); } From 7f27baf18390ad63049593c639a4ce23f848ab71 Mon Sep 17 00:00:00 2001 From: gnattu Date: Fri, 26 Apr 2024 06:13:15 +0800 Subject: [PATCH 2/6] Fix lint --- src/scripts/browserDeviceProfile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index f3908d9999..53bb1451da 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -122,7 +122,6 @@ function supportsAc3InHls(videoTestElement) { } function supportsMp3InHls(videoTestElement) { - if (videoTestElement.canPlayType) { return videoTestElement.canPlayType('application/x-mpegurl; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, '') || videoTestElement.canPlayType('application/vnd.apple.mpegURL; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, ''); From adf6530650e5c98e8e2559218cd4b8f3b66d9b3c Mon Sep 17 00:00:00 2001 From: gnattu Date: Fri, 26 Apr 2024 22:24:05 +0800 Subject: [PATCH 3/6] Add options.supportsMp3InTs to allow client override --- src/scripts/browserDeviceProfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index 53bb1451da..a060ce3a4d 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -488,7 +488,7 @@ export default function (options) { // Safari is the only browser that supports mp3 with HLS, but only in mpegts container. // The detect function will return false on Safari, which reflects the fmp4 support, so we have to hard-code it here. - if (browser.safari || canPlayMp3VideoAudioInHls) { + if (browser.safari || canPlayMp3VideoAudioInHls || options.supportsMp3InTs) { hlsInTsVideoAudioCodecs.push('mp3'); } From 13b5c071b88d36eff71acad4d5cddfdcd1d79e75 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 30 Apr 2024 08:25:54 +0800 Subject: [PATCH 4/6] relax the mp3 compatability check for mp3 in hls-ts --- src/scripts/browserDeviceProfile.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index a060ce3a4d..a0535e9a62 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -123,8 +123,8 @@ function supportsAc3InHls(videoTestElement) { function supportsMp3InHls(videoTestElement) { if (videoTestElement.canPlayType) { - return videoTestElement.canPlayType('application/x-mpegurl; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, '') - || videoTestElement.canPlayType('application/vnd.apple.mpegURL; codecs="avc1.42E01E, mp4a.40.34"').replace(/no/, ''); + return videoTestElement.canPlayType('application/x-mpegurl; codecs="avc1.64001E, mp4a.40.34"').replace(/no/, '') + || videoTestElement.canPlayType('application/vnd.apple.mpegURL; codecs="avc1.64001E, mp4a.40.34"').replace(/no/, ''); } return false; @@ -486,9 +486,8 @@ export default function (options) { videoAudioCodecs.push('mp3'); } - // Safari is the only browser that supports mp3 with HLS, but only in mpegts container. - // The detect function will return false on Safari, which reflects the fmp4 support, so we have to hard-code it here. - if (browser.safari || canPlayMp3VideoAudioInHls || options.supportsMp3InTs) { + // Safari supports mp3 with HLS, but only in mpegts container, and the supportsMp3VideoAudio will return false. + if (browser.safari || supportsMp3VideoAudio) { hlsInTsVideoAudioCodecs.push('mp3'); } From 70c8b439b119dc6f7fca484c04dcd553e611e48d Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 30 Apr 2024 17:09:21 +0800 Subject: [PATCH 5/6] Disable mp3 in hls-ts for ps4 --- src/scripts/browserDeviceProfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index a0535e9a62..1dfb5ea717 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -487,7 +487,7 @@ export default function (options) { } // Safari supports mp3 with HLS, but only in mpegts container, and the supportsMp3VideoAudio will return false. - if (browser.safari || supportsMp3VideoAudio) { + if (!browser.ps4 && (browser.safari || supportsMp3VideoAudio)) { hlsInTsVideoAudioCodecs.push('mp3'); } From 762ea7f147b80936fa997891b82a18697a29a894 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 30 Apr 2024 18:46:48 +0800 Subject: [PATCH 6/6] Change check order to match the comment Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/scripts/browserDeviceProfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index 1dfb5ea717..dce9a02cb4 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -487,7 +487,7 @@ export default function (options) { } // Safari supports mp3 with HLS, but only in mpegts container, and the supportsMp3VideoAudio will return false. - if (!browser.ps4 && (browser.safari || supportsMp3VideoAudio)) { + if (browser.safari || (supportsMp3VideoAudio && !browser.ps4)) { hlsInTsVideoAudioCodecs.push('mp3'); }