Merge pull request #724 from nyanmisaka/master

Update and fix some canPlayType
This commit is contained in:
Vasily 2020-01-30 14:17:46 +03:00 committed by GitHub
commit af75183d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,12 +18,15 @@ define(['browser'], function (browser) {
}
}
// Unfortunately haven't yet found a canPlayType for proper detection
if (browser.iOS && (browser.iOSVersion || 0) >= 11) {
return true;
if (browser.ps4) {
return false;
}
return !!(videoTestElement.canPlayType && videoTestElement.canPlayType('video/hevc; codecs="hevc, aac"').replace(/no/, ''));
return !!videoTestElement.canPlayType &&
(videoTestElement.canPlayType('video/mp4; codecs="hvc1.1.L120"').replace(/no/, '') ||
videoTestElement.canPlayType('video/mp4; codecs="hev1.1.L120"').replace(/no/, '') ||
videoTestElement.canPlayType('video/mp4; codecs="hvc1.1.0.L120"').replace(/no/, '') ||
videoTestElement.canPlayType('video/mp4; codecs="hev1.1.0.L120"').replace(/no/, ''));
}
var _supportsTextTracks;
@ -41,7 +44,7 @@ define(['browser'], function (browser) {
}
var _canPlayHls;
function canPlayHls(src) {
function canPlayHls() {
if (_canPlayHls == null) {
_canPlayHls = canPlayNativeHls() || canPlayHlsWithMSE();
}
@ -64,12 +67,8 @@ define(['browser'], function (browser) {
}
function canPlayHlsWithMSE() {
if (window.MediaSource != null) {
// text tracks dont work with this in firefox
return true;
}
return false;
// text tracks dont work with this in firefox
return window.MediaSource != null;
}
function supportsAc3(videoTestElement) {
@ -88,30 +87,45 @@ define(['browser'], function (browser) {
return videoTestElement.canPlayType('audio/mp4; codecs="ec-3"').replace(/no/, '');
}
function supportsAc3InHls(videoTestElement) {
if (browser.tizen || browser.orsay || browser.web0s) {
return true;
}
if (!!videoTestElement.canPlayType) {
return videoTestElement.canPlayType('application/x-mpegurl; codecs="avc1.42E01E, ac-3"').replace(/no/, '') ||
videoTestElement.canPlayType('application/vnd.apple.mpegURL; codecs="avc1.42E01E, ac-3"').replace(/no/, '');
}
return false;
}
function canPlayAudioFormat(format) {
var typeString;
if (format === 'flac') {
if (browser.tizen || browser.orsay || browser.web0s) {
return true;
}
if (browser.edgeUwp) {
if (browser.tizen || browser.orsay || browser.web0s || browser.edgeUwp) {
return true;
}
} else if (format === 'wma') {
if (browser.tizen || browser.orsay) {
if (browser.tizen || browser.orsay || browser.edgeUwp) {
return true;
}
if (browser.edgeUwp) {
} else if (format === 'asf') {
if (browser.tizen || browser.web0s || browser.edgeUwp) {
return true;
}
} else if (format === 'opus') {
typeString = 'audio/ogg; codecs="opus"';
if (document.createElement('audio').canPlayType(typeString).replace(/no/, '')) {
return true;
if (!browser.web0s) {
typeString = 'audio/ogg; codecs="opus"';
return !!document.createElement('audio').canPlayType(typeString).replace(/no/, '');
}
return false;
} else if (format === 'alac') {
if (browser.iOS || browser.osx) {
return true;
}
} else if (format === 'mp2') {
// For now
return false;
@ -125,11 +139,7 @@ define(['browser'], function (browser) {
typeString = 'audio/' + format;
}
if (document.createElement('audio').canPlayType(typeString).replace(/no/, '')) {
return true;
}
return false;
return !!document.createElement('audio').canPlayType(typeString).replace(/no/, '');
}
function testCanPlayMkv(videoTestElement) {
@ -142,8 +152,6 @@ define(['browser'], function (browser) {
return true;
}
var userAgent = navigator.userAgent.toLowerCase();
// Unfortunately there's no real way to detect mkv support
if (browser.chrome) {
// Not supported on opera tv
@ -151,6 +159,8 @@ define(['browser'], function (browser) {
return false;
}
var userAgent = navigator.userAgent.toLowerCase();
// Filter out browsers based on chromium that don't support mkv
if (userAgent.indexOf('vivaldi') !== -1 || userAgent.indexOf('opera') !== -1) {
return false;
@ -199,15 +209,15 @@ define(['browser'], function (browser) {
switch (container) {
case 'asf':
supported = browser.tizen || browser.orsay || browser.edgeUwp;
supported = browser.tizen || browser.orsay || browser.web0s || browser.edgeUwp;
videoAudioCodecs = [];
break;
case 'avi':
supported = browser.tizen || browser.orsay || browser.edgeUwp;
supported = browser.tizen || browser.orsay || browser.web0s || browser.edgeUwp;
break;
case 'mpg':
case 'mpeg':
supported = browser.edgeUwp || browser.tizen || browser.orsay;
supported = browser.tizen || browser.orsay || browser.web0s || browser.edgeUwp;
break;
case 'flv':
supported = browser.tizen || browser.orsay;
@ -223,7 +233,7 @@ define(['browser'], function (browser) {
supported = browser.tizen || browser.orsay;
break;
case 'mov':
supported = browser.tizen || browser.orsay || browser.chrome || browser.edgeUwp;
supported = browser.tizen || browser.orsay || browser.web0s || browser.chrome || browser.edgeUwp;
videoCodecs.push('h264');
break;
case 'm2ts':
@ -259,16 +269,12 @@ define(['browser'], function (browser) {
break;
}
if (!supported) {
return null;
}
return {
return supported ? {
Container: profileContainer,
Type: 'Video',
VideoCodec: videoCodecs.join(','),
AudioCodec: videoAudioCodecs.join(',')
};
} : null;
}
function getMaxBitrate() {
@ -369,8 +375,7 @@ define(['browser'], function (browser) {
// This works in edge desktop, but not mobile
// TODO: Retest this on mobile
var supportsAc3InHls = (!browser.edge || !browser.touch || browser.edgeUwp);
if (supportsAc3InHls) {
if (supportsAc3InHls(videoTestElement)) {
hlsVideoAudioCodecs.push('ac3');
if (eAc3) {
hlsVideoAudioCodecs.push('eac3');
@ -471,6 +476,7 @@ define(['browser'], function (browser) {
mp4VideoCodecs.push('h264');
hlsVideoCodecs.push('h264');
}
if (canPlayH265(videoTestElement, options)) {
mp4VideoCodecs.push('h265');
mp4VideoCodecs.push('hevc');
@ -553,10 +559,10 @@ define(['browser'], function (browser) {
});
}
// aac also appears in the m4a container
// aac also appears in the m4a and m4b container
if (audioFormat === 'aac' || audioFormat === 'alac') {
profile.DirectPlayProfiles.push({
Container: 'm4a',
Container: 'm4a,m4b',
AudioCodec: audioFormat,
Type: 'Audio'
});
@ -648,7 +654,7 @@ define(['browser'], function (browser) {
});
}
if (canPlayHls() && options.enableHls !== false) {
if (canPlayHls() && hlsVideoAudioCodecs.length && options.enableHls !== false) {
profile.TranscodingProfiles.push({
Container: 'ts',
Type: 'Video',
@ -743,11 +749,21 @@ define(['browser'], function (browser) {
});
}
var maxH264Level = browser.chromecast ? 42 : 51;
var maxH264Level = 42;
var h264Profiles = 'high|main|baseline|constrained baseline';
if (maxH264Level >= 51 && browser.chrome && !browser.osx) {
h264Profiles += '|high 10';
if (browser.tizen || browser.orsay || browser.web0s ||
videoTestElement.canPlayType('video/mp4; codecs="avc1.640833"').replace(/no/, '')) {
maxH264Level = 51;
}
if (browser.tizen || browser.orsay ||
videoTestElement.canPlayType('video/mp4; codecs="avc1.6e0033"').replace(/no/, '')) {
// These tests are passing in safari, but playback is failing
if (!browser.safari && !browser.iOS && !browser.web0s && !browser.edge) {
h264Profiles += '|high 10';
}
}
profile.CodecProfiles.push({
@ -763,12 +779,14 @@ define(['browser'], function (browser) {
{
Condition: 'EqualsAny',
Property: 'VideoProfile',
Value: h264Profiles
Value: h264Profiles,
IsRequired: false
},
{
Condition: 'LessThanEqual',
Property: 'VideoLevel',
Value: maxH264Level.toString()
Value: maxH264Level.toString(),
IsRequired: false
}
]
});