Skip to content

Commit

Permalink
Fix isLive and seekRange for native HLS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joeyparrish committed Apr 26, 2019
1 parent 182a775 commit 4082eb1
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions lib/player.js
Expand Up @@ -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;
};


Expand Down Expand Up @@ -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};
};


Expand Down

0 comments on commit 4082eb1

Please sign in to comment.