1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fix MP3 audio playback capability checking with HLS

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.
This commit is contained in:
gnattu 2024-04-26 06:00:24 +08:00
parent b1f786b270
commit 193c89802e

View file

@ -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');
}