From d5aec7c6c65a62e2f3d50db520d31fa7b9a73028 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Mon, 23 May 2016 23:25:43 +0200 Subject: [PATCH] Only add sources if the type is supported by a Tech There is not much use in adding sources that we cannot play, so filter them out. Backwards compatible with Tech's that do not yet support canPlayType(). Fixes #15 --- lib/videojs-resolution-switcher.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/videojs-resolution-switcher.js b/lib/videojs-resolution-switcher.js index 5b1448e..901add1 100644 --- a/lib/videojs-resolution-switcher.js +++ b/lib/videojs-resolution-switcher.js @@ -178,6 +178,15 @@ player.controlBar.resolutionSwitcher.dispose(); delete player.controlBar.resolutionSwitcher; } + // Only add those sources which we can (maybe) play + src = src.filter( function(source) { + try { + return ( player.canPlayType( source.type ) !== '' ); + } catch (e) { + // If a Tech doesn't yet have canPlayType just add it + return true; + } + }); //Sort sources src = src.sort(compareResolutions); groupedSrc = bucketSources(src);