iOS 第三方浏览器(Chrome/Firefox/Edge/Opera)改走 TS 兼容流:能力声明隐藏原生 HLS,服务端规划 legacy TS 通道,绕开 fMP4 黑屏问题
This commit is contained in:
@@ -25,7 +25,10 @@
|
|||||||
const supported = type => playable(type) || mse(type);
|
const supported = type => playable(type) || mse(type);
|
||||||
const videoCodecs = {h264: 'avc1.42E01E', hevc: 'hvc1.1.6.L120.B0', av1: 'av01.0.08M.08', vp9: 'vp09.00.10.08'};
|
const videoCodecs = {h264: 'avc1.42E01E', hevc: 'hvc1.1.6.L120.B0', av1: 'av01.0.08M.08', vp9: 'vp09.00.10.08'};
|
||||||
const audioCodecs = {aac: 'mp4a.40.2', mp3: 'mp4a.69', ac3: 'ac-3', eac3: 'ec-3', opus: 'opus'};
|
const audioCodecs = {aac: 'mp4a.40.2', mp3: 'mp4a.69', ac3: 'ac-3', eac3: 'ec-3', opus: 'opus'};
|
||||||
return {mp4: playable('video/mp4'), nativeHls: native(), hlsjs: Boolean(environment.Hls?.isSupported()),
|
// iOS 上的第三方浏览器(Chrome/Firefox/Edge/Opera)自带的媒体栈对 fMP4 HLS 兼容性差,
|
||||||
|
// 会黑屏缓冲;让服务端按无 HLS 通道规划,走 legacy 的 TS 实时转码(hls/open)。
|
||||||
|
const thirdPartyIOS = touchApple && /CriOS|FxiOS|EdgiOS|OPT\//.test(agent.userAgent || '');
|
||||||
|
return {mp4: playable('video/mp4'), nativeHls: native() && !thirdPartyIOS, hlsjs: Boolean(environment.Hls?.isSupported()),
|
||||||
video: Object.keys(videoCodecs).filter(key => supported('video/mp4; codecs="' + videoCodecs[key] + '"')),
|
video: Object.keys(videoCodecs).filter(key => supported('video/mp4; codecs="' + videoCodecs[key] + '"')),
|
||||||
audio: Object.keys(audioCodecs).filter(key => supported('audio/mp4; codecs="' + audioCodecs[key] + '"'))};
|
audio: Object.keys(audioCodecs).filter(key => supported('audio/mp4; codecs="' + audioCodecs[key] + '"'))};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,3 +33,17 @@ test('remux requires compatible H.264 profiles and never replaces iOS HLS', () =
|
|||||||
limited.MediaSource.isTypeSupported = () => {throw new Error('probe unavailable');};
|
limited.MediaSource.isTypeSupported = () => {throw new Error('probe unavailable');};
|
||||||
assert.equal(capabilities(limited, native, {}).remux(), false);
|
assert.equal(capabilities(limited, native, {}).remux(), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('third-party iOS browsers hide native HLS so the server plans the TS path', () => {
|
||||||
|
for (const ua of ['iPhone CriOS/154.0.8037.41 Mobile/15E148 Safari/604.1',
|
||||||
|
'iPhone FxiOS/130.0 Mobile/15E148 Safari/605.1.15',
|
||||||
|
'iPhone EdgiOS/130.0.1 Mobile/15E148 Safari/605.1.15']) {
|
||||||
|
const view = capabilities(mse(true), native, {userAgent: ua});
|
||||||
|
assert.equal(view.describe().nativeHls, false);
|
||||||
|
assert.equal(view.choose(type), 'hls');
|
||||||
|
}
|
||||||
|
const safari = capabilities(mse(true), native, {userAgent: 'iPhone Version/27.0 Mobile/15E148 Safari/604.1'});
|
||||||
|
assert.equal(safari.describe().nativeHls, true);
|
||||||
|
const opera = capabilities(mse(true), native, {userAgent: 'iPhone OPT/2.4.0 Mobile/15E148 Safari/605.1.15'});
|
||||||
|
assert.equal(opera.describe().nativeHls, false);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user