From 4082eb17f434840b9993eb1cbf2bba3c3984d1f4 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 25 Apr 2019 16:09:48 -0700 Subject: [PATCH] Fix isLive and seekRange for native HLS By fixing the definitions of isLive and seekRange for native HLS and other src= playbacks, the UI for live streams with native HLS is now working correctly on Safari. Issue #382 Issue #997 Change-Id: I3d4f49ebe31a543c75f8607e7a194095ef198c0a --- lib/player.js | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/player.js b/lib/player.js index 5a9df00c9d..c5e69f6f31 100644 --- a/lib/player.js +++ b/lib/player.js @@ -2510,9 +2510,16 @@ shaka.Player.prototype.getManifestUri = function() { * @export */ shaka.Player.prototype.isLive = function() { - return this.loadMode_ == shaka.Player.LoadMode.MEDIA_SOURCE ? - this.manifest_.presentationTimeline.isLive() : - false; + if (this.manifest_) { + return this.manifest_.presentationTimeline.isLive(); + } + + // For native HLS, the duration for live streams seems to be Infinity. + if (this.video_ && this.video_.src) { + return this.video_.duration == Infinity; + } + + return false; }; @@ -2571,23 +2578,28 @@ shaka.Player.prototype.isAudioOnly = function() { * @export */ shaka.Player.prototype.seekRange = function() { - // If we have loaded content with src=, we assume that the whole presentation - // is seekable. For mp4, this is always the case. For HLS, this may not always - // be the case, but there is no way for us to get this information. - if (this.loadMode_ == shaka.Player.LoadMode.SRC_EQUALS) { - return {'start': 0, 'end': this.video_.duration}; - } + if (this.manifest_) { + const timeline = this.manifest_.presentationTimeline; - if (this.loadMode_ != shaka.Player.LoadMode.MEDIA_SOURCE) { - return {'start': 0, 'end': 0}; + return { + 'start': timeline.getSeekRangeStart(), + 'end': timeline.getSeekRangeEnd(), + }; } - const timeline = this.manifest_.presentationTimeline; + // If we have loaded content with src=, we ask the video element for its + // seekable range. This covers both plain mp4s and native HLS playbacks. + if (this.video_ && this.video_.src) { + const seekable = this.video_.seekable; + if (seekable.length) { + return { + 'start': seekable.start(0), + 'end': seekable.end(seekable.length - 1), + }; + } + } - return { - 'start': timeline.getSeekRangeStart(), - 'end': timeline.getSeekRangeEnd(), - }; + return {'start': 0, 'end': 0}; };