From f36367abd9b1537b3b01463347d01b186844fbef Mon Sep 17 00:00:00 2001 From: Anton Schubert Date: Sat, 30 Dec 2017 17:51:44 +0100 Subject: update shaka-player to 2.3.0, improve source-selection code for multiquality player --- template/assemblies/player/dash.phtml | 56 ++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'template/assemblies') 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 ? 'getDashManifestUrl())?>' : 'getHLSPlaylistUrl())?>'; - selectRelay(cdnUrl, function(relayUrl) { - createPlayer([{source: relayUrl}]); - }); - } else { - // Default to simple WebM playback - var player = createPlayer([{ + selectRelay("getDashManifestUrl())?>", function(relay) { + // WebM fallback + var sources = [{ source: "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: "getHLSPlaylistUrl())?>" + }); + } + + // VP9 dash player + if (hasMSE && MediaSource.isTypeSupported('video/webm; codecs="vp9,vorbis"')) { + sources.unshift({ + source: "getDashManifestUrl())?>" + }); + } + + createPlayer(sources); + }); }()); -- cgit v1.2.3