diff options
author | Anton Schubert | 2017-12-30 17:51:44 +0100 |
---|---|---|
committer | MaZderMind | 2018-01-24 23:44:40 +0100 |
commit | f36367abd9b1537b3b01463347d01b186844fbef (patch) | |
tree | f36dc1e17fcded998f35562976b47ec47b3d7609 /template/assemblies/player/dash.phtml | |
parent | 080c1d085e4311b16ba7cfec47bddb9d1dc64243 (diff) |
update shaka-player to 2.3.0, improve source-selection code for multiquality player
Diffstat (limited to '')
-rw-r--r-- | template/assemblies/player/dash.phtml | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/template/assemblies/player/dash.phtml b/template/assemblies/player/dash.phtml index a5344c7..24a3df6 100644 --- a/template/assemblies/player/dash.phtml +++ b/template/assemblies/player/dash.phtml @@ -25,9 +25,7 @@ setTimeout(selectRelay.bind(null, url, cb), 2000); console.log("selected relay", relay); - var proto = url.match(/^https?:\/\//), - path = "/" + url.split("/").slice(3).join("/"); - cb(proto + relay + path) + cb(relay); }, error: function(err) { console.error("Error while selecting relay: ", err.status, err.statusText) @@ -36,6 +34,12 @@ }); } + var getRelayUrl = function(relay, cdnUrl) { + var proto = cdnUrl.match(/^https?:\/\//), + path = "/" + cdnUrl.split("/").slice(3).join("/"); + return proto + relay + path; + } + var createPlayer = function(sources) { return new Clappr.Player({ sources: sources, @@ -47,7 +51,12 @@ }, streaming: { rebufferingGoal: 12, - jumpLargeGaps: true + jumpLargeGaps: true, + + // Todo: handle streaming failure + // failureCallback: function() { + // console.log("streaming failure callback", arguments) + // } } }, levelSelectorConfig: { @@ -74,24 +83,29 @@ }); } - var hasMSE = 'MediaSource' in window, - hasWebM = document.createElement('video').canPlayType('video/webm; codecs=vp9,vorbis') != "", - nativeHLS = document.createElement('video').canPlayType('application/vnd.apple.mpegURL') != ""; - - // Play Multiquality only if supported - if (hasMSE || nativeHLS) { - // Detect WebM capability, Select relay, Create player - var cdnUrl = hasWebM ? '<?=h($room->getDashManifestUrl())?>' : '<?=h($room->getHLSPlaylistUrl())?>'; - selectRelay(cdnUrl, function(relayUrl) { - createPlayer([{source: relayUrl}]); - }); - } else { - // Default to simple WebM playback - var player = createPlayer([{ + selectRelay("<?=h($room->getDashManifestUrl())?>", function(relay) { + // WebM fallback + var sources = [{ source: "<?=h($stream->getVideoUrl('webm', 'hd'))?>", - mimeType: "video/webm" - }]); - } + }]; + + // HLS playlist + var hasMSE = "MediaSource" in window; + if (hasMSE || document.createElement('video').canPlayType('application/vnd.apple.mpegURL') != "") { + sources.unshift({ + source: "<?=h($room->getHLSPlaylistUrl())?>" + }); + } + + // VP9 dash player + if (hasMSE && MediaSource.isTypeSupported('video/webm; codecs="vp9,vorbis"')) { + sources.unshift({ + source: "<?=h($room->getDashManifestUrl())?>" + }); + } + + createPlayer(sources); + }); }()); </script> |