Skip to content

Commit

Permalink
Clear tracks when resuming live playback in html5
Browse files Browse the repository at this point in the history
Use item/model minDvrWindow
JW8-2289
  • Loading branch information
Rob Walch committed Oct 25, 2018
1 parent 6a61f26 commit 8c0a443
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/js/providers/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const HTML5_SRC_RESET = 224005;
const HTML5_NETWORK_ERROR = 221000;

const clearTimeout = window.clearTimeout;
const MIN_DVR_DURATION = 120;
const _name = 'html5';
const noop = function () {};

Expand Down Expand Up @@ -71,6 +70,8 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {

const _this = this;

let minDvrWindow = _playerConfig.minDvrWindow || 120;

const MediaEvents = {
progress() {
VideoEvents.progress.call(_this);
Expand Down Expand Up @@ -249,7 +250,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
return _videotag.duration === Infinity;
},
isDVR() {
return _this.isLive() && (_getSeekableEnd() - _getSeekableStart()) >= MIN_DVR_DURATION;
return _this.isLive() && ((_getSeekableEnd() - _getSeekableStart()) >= minDvrWindow);
}
});

Expand Down Expand Up @@ -324,7 +325,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
const end = _getSeekableEnd();
if (_this.isLive() && end) {
const seekableDuration = end - _getSeekableStart();
if (seekableDuration !== Infinity && seekableDuration > MIN_DVR_DURATION) {
if (seekableDuration !== Infinity && seekableDuration > minDvrWindow) {
// Player interprets negative duration as DVR
duration = -seekableDuration;
}
Expand Down Expand Up @@ -367,9 +368,10 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
return publicLevels;
}

function _setLevels(levels) {
_levels = levels;
_currentQuality = _pickInitialQuality(levels);
function setPlaylistItem(item) {
minDvrWindow = item.minDvrWindow || minDvrWindow;
_levels = item.sources;
_currentQuality = _pickInitialQuality(_levels);
}

function _pickInitialQuality(levels) {
Expand Down Expand Up @@ -397,6 +399,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
function _play() {
const resumingPlayback = _videotag.paused && _videotag.played && _videotag.played.length;
if (resumingPlayback && _this.isLive() && !_this.isDVR()) {
_this.clearTracks();
_videotag.load();
}
return _videotag.play() || createPlayPromise(_videotag);
Expand Down Expand Up @@ -516,7 +519,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
};

this.init = function(item) {
_setLevels(item.sources);
setPlaylistItem(item);
const source = _levels[_currentQuality];
_androidHls = isAndroidHls(source);
if (_androidHls) {
Expand All @@ -534,7 +537,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
};

this.preload = function(item) {
_setLevels(item.sources);
setPlaylistItem(item);
const source = _levels[_currentQuality];
const preload = source.preload || 'metadata';
if (preload !== 'none') {
Expand All @@ -544,7 +547,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
};

this.load = function(item) {
_setLevels(item.sources);
setPlaylistItem(item);
_completeLoad(item.starttime);
this.setupSideloadedTracks(item.tracks);
};
Expand All @@ -561,7 +564,7 @@ function VideoProvider(_playerId, _playerConfig, mediaElement) {
if (unpausing && _this.isLive()) {
const end = _getSeekableEnd();
const seekableDuration = end - _getSeekableStart();
const isLiveNotDvr = seekableDuration < MIN_DVR_DURATION;
const isLiveNotDvr = seekableDuration < minDvrWindow;
const behindLiveEdge = end - _videotag.currentTime;
if (isLiveNotDvr && end && (behindLiveEdge > 15 || behindLiveEdge < 0)) {
// resume playback at edge of live stream
Expand Down

0 comments on commit 8c0a443

Please sign in to comment.