Skip to content

Commit

Permalink
Seek after clearing a buffer. Workaround for a Chrome bug.
Browse files Browse the repository at this point in the history
A bug in Chrome makes video feed freeze for a while after a buffer
is cleared. Seeking helps to avoid freezing.
A bug on Chrome: http://crbug.com/651904

Change-Id: I80d9139cb02e859d9a0165235c9868d9afa8adfa
  • Loading branch information
ismena committed Oct 3, 2016
1 parent c17b1f1 commit 10b3dd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/media/playhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ shaka.media.Playhead.prototype.onSeeking_ = function() {
var targetTime = this.reposition_(currentTime);

if (Math.abs(targetTime - currentTime) > 0.001) {
this.movePlayhead_(currentTime, targetTime);
this.movePlayhead(currentTime, targetTime);
return;
}

Expand All @@ -370,7 +370,7 @@ shaka.media.Playhead.prototype.onPlaying_ = function() {
var targetTime = this.reposition_(currentTime);

if (Math.abs(targetTime - currentTime) > 0.001)
this.movePlayhead_(currentTime, targetTime);
this.movePlayhead(currentTime, targetTime);
};


Expand Down Expand Up @@ -440,9 +440,8 @@ shaka.media.Playhead.prototype.reposition_ = function(currentTime) {
*
* @param {number} currentTime
* @param {number} targetTime
* @private
*/
shaka.media.Playhead.prototype.movePlayhead_ = function(
shaka.media.Playhead.prototype.movePlayhead = function(
currentTime, targetTime) {
shaka.log.debug('Moving playhead...',
'currentTime=' + currentTime,
Expand Down
11 changes: 11 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,17 @@ shaka.media.StreamingEngine.prototype.clearBuffer_ = function(
mediaState.lastSegmentReference = null;
mediaState.clearingBuffer = false;
this.scheduleUpdate_(mediaState, 0);

// A workaround for a chrome bug: http://crbug.com/651904
// Video freezes for a while after buffer is cleared.
// Advancing the playhead a little allows to avoid the freeze.
// NOTE: Opera has the same issue as it is based on Chrome.
// It also returns true on window.chrome and will unfreeze
// after seeking.
if (window.chrome) {
var currentTime = this.playhead_.getTime();
this.playhead_.movePlayhead(currentTime, currentTime + 0.1);
}
}.bind(this));
};

Expand Down

0 comments on commit 10b3dd0

Please sign in to comment.