diff --git a/src/controller/base-stream-controller.js b/src/controller/base-stream-controller.js index ae3348d7cd1..e798c5a122b 100644 --- a/src/controller/base-stream-controller.js +++ b/src/controller/base-stream-controller.js @@ -63,9 +63,7 @@ export default class BaseStreamController extends TaskLoop { const currentTime = media ? media.currentTime : null; const bufferInfo = BufferHelper.bufferInfo(mediaBuffer || media, currentTime, this.config.maxBufferHole); - if (Number.isFinite(currentTime)) { - logger.log(`media seeking to ${currentTime.toFixed(3)}`); - } + logger.log(`media seeking to ${Number.isFinite(currentTime) ? currentTime.toFixed(3) : currentTime}`); if (state === State.FRAG_LOADING) { let fragCurrent = this.fragCurrent; diff --git a/src/controller/stream-controller.js b/src/controller/stream-controller.js index a8f51e5f893..1d5371150f3 100644 --- a/src/controller/stream-controller.js +++ b/src/controller/stream-controller.js @@ -1336,8 +1336,9 @@ class StreamController extends BaseStreamController { * @private */ _seekToStartPos () { - const { media, startPosition } = this; + const { media } = this; const currentTime = media.currentTime; + let startPosition = this.startPosition; // only adjust currentTime if different from startPosition or if startPosition not buffered // at that stage, there should be only one buffered range, as we reach that code after first fragment has been buffered if (currentTime !== startPosition && startPosition >= 0) { @@ -1345,6 +1346,13 @@ class StreamController extends BaseStreamController { logger.log(`could not seek to ${startPosition}, already seeking at ${currentTime}`); return; } + const bufferStart = media.buffered.length ? media.buffered.start(0) : 0; + const delta = bufferStart - startPosition; + if (delta > 0 && delta < this.config.maxBufferHole) { + logger.log(`adjusting start position by ${delta} to match buffer start`); + startPosition += delta; + this.startPosition = startPosition; + } logger.log(`seek to target start position ${startPosition} from current time ${currentTime}. ready state ${media.readyState}`); media.currentTime = startPosition; } diff --git a/tests/unit/controller/stream-controller.js b/tests/unit/controller/stream-controller.js index 2b3609807cc..cf3c1b9a0a6 100644 --- a/tests/unit/controller/stream-controller.js +++ b/tests/unit/controller/stream-controller.js @@ -198,6 +198,7 @@ describe('StreamController', function () { describe('checkBuffer', function () { const sandbox = sinon.createSandbox(); + let bufStart = 5; beforeEach(function () { streamController.gapController = { @@ -205,6 +206,9 @@ describe('StreamController', function () { }; streamController.media = { buffered: { + start () { + return bufStart; + }, length: 1 } };