From 1023132fb0eb8edb5787c808f3a6f8ef79253a8d Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Wed, 7 Sep 2022 23:50:27 -0700 Subject: [PATCH] Fix seek to live start regression introduced in #4864 --- src/controller/base-stream-controller.ts | 3 +++ src/controller/stream-controller.ts | 11 ++--------- tests/unit/controller/stream-controller.ts | 12 ++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/controller/base-stream-controller.ts b/src/controller/base-stream-controller.ts index 36a243b5da9..9caab4a0379 100644 --- a/src/controller/base-stream-controller.ts +++ b/src/controller/base-stream-controller.ts @@ -524,10 +524,13 @@ export default class BaseStreamController this.fragCurrent === this.fragPrevious ) { this.loadedmetadata = true; + this.seekToStartPos(); } this.tick(); } + protected seekToStartPos() {} + protected _handleFragmentLoadComplete(fragLoadedEndData: PartsLoadedData) { const { transmuxer } = this; if (!transmuxer) { diff --git a/src/controller/stream-controller.ts b/src/controller/stream-controller.ts index 235ebad49cd..db4c51df6e4 100644 --- a/src/controller/stream-controller.ts +++ b/src/controller/stream-controller.ts @@ -917,13 +917,7 @@ export default class StreamController return; } - // Check combined buffer - const buffered = BufferHelper.getBuffered(media); - - if (!this.loadedmetadata && buffered.length) { - this.loadedmetadata = true; - this.seekToStartPos(); - } else { + if (this.loadedmetadata || !BufferHelper.getBuffered(media).length) { // Resolve gaps using the main buffer, whose ranges are the intersections of the A/V sourcebuffers const activeFrag = this.state !== State.IDLE ? this.fragCurrent : null; gapController.poll(this.lastCurrentTime, activeFrag); @@ -972,9 +966,8 @@ export default class StreamController /** * Seeks to the set startPosition if not equal to the mediaElement's current time. - * @private */ - private seekToStartPos() { + protected seekToStartPos() { const { media } = this; if (!media) { return; diff --git a/tests/unit/controller/stream-controller.ts b/tests/unit/controller/stream-controller.ts index 082c64cc2a4..a0e455139fe 100644 --- a/tests/unit/controller/stream-controller.ts +++ b/tests/unit/controller/stream-controller.ts @@ -377,11 +377,19 @@ describe('StreamController', function () { streamController['checkBuffer'](); }); - it('should seek to start pos when metadata has not yet been loaded', function () { + it('should seek to start pos when data is first loaded', function () { + const firstFrag = new Fragment(PlaylistLevelType.MAIN, ''); + firstFrag.duration = 5.0; + firstFrag.level = 1; + firstFrag.start = 0; + firstFrag.sn = 1; + firstFrag.cc = 0; // @ts-ignore const seekStub = sandbox.stub(streamController, 'seekToStartPos'); streamController['loadedmetadata'] = false; - streamController['checkBuffer'](); + streamController['fragCurrent'] = streamController['fragPrevious'] = + firstFrag; + streamController['fragBufferedComplete'](firstFrag, null); expect(seekStub).to.have.been.calledOnce; expect(streamController['loadedmetadata']).to.be.true; });