Skip to content

Instantly share code, notes, and snippets.

@arturparkhisenko
Created March 29, 2023 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturparkhisenko/fb1a9756beb75087984067b6a7edafdf to your computer and use it in GitHub Desktop.
Save arturparkhisenko/fb1a9756beb75087984067b6a7edafdf to your computer and use it in GitHub Desktop.
Whether the browser has built-in HLS support.
// From https://github.com/videojs/http-streaming/blob/d258fae646a3a4a6dc2ba26c729710dd8f39876a/src/videojs-http-streaming.js#L430-L464
/**
* Whether the browser has built-in HLS support.
*/
window._supportsNativeHls = (function() {
if (!document || !document.createElement) {
return false;
}
const video = document.createElement('video');
// HLS manifests can go by many mime-types
const canPlay = [
// Apple santioned
'application/vnd.apple.mpegurl',
// Apple sanctioned for backwards compatibility
'audio/mpegurl',
// Very common
'audio/x-mpegurl',
// Very common
'application/x-mpegurl',
// Included for completeness
'video/x-mpegurl',
'video/mpegurl',
'application/mpegurl'
];
return canPlay.some(function(canItPlay) {
return (/maybe|probably/i).test(video.canPlayType(canItPlay));
});
}());
console.warn('window._supportsNativeHls?', window._supportsNativeHls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment