Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,7 @@ class AudioStreamController
}

protected onTickEnd() {
const { media } = this;
if (!media?.readyState) {
// Exit early if we don't have media or if the media hasn't buffered anything yet (readyState 0)
return;
}

this.lastCurrentTime = media.currentTime;
super.onTickEnd();
this.checkFragmentChanged();
}

Expand Down
17 changes: 11 additions & 6 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ export default class BaseStreamController
hls.off(Events.ERROR, this.onError, this);
}

protected doTick() {
this.onTickEnd();
}
protected doTick() {}

protected onTickEnd() {}
protected onTickEnd() {
const { media } = this;
if (media?.readyState && media.seeking === false) {
this.lastCurrentTime = media.currentTime;
}
}

public startLoad(startPosition: number): void {}

Expand Down Expand Up @@ -380,7 +383,7 @@ export default class BaseStreamController
this.levelLastLoaded =
this.fragCurrent =
null;
this.lastCurrentTime = 0;
this.lastCurrentTime = this.nextLoadPosition = 0;
this.startPosition = -1;
this.startFragRequested = false;
}
Expand Down Expand Up @@ -477,6 +480,8 @@ export default class BaseStreamController
this.nextLoadPosition = currentTime;
if (bufferEmpty) {
this.startPosition = currentTime;
} else {
this.lastCurrentTime = currentTime;
}
}

Expand All @@ -489,7 +494,7 @@ export default class BaseStreamController
protected onMediaEnded = () => {
// reset startPosition and lastCurrentTime to restart playback @ stream beginning
this.log(`setting startPosition to 0 because media ended`);
this.startPosition = this.lastCurrentTime = 0;
this.startPosition = this.nextLoadPosition = this.lastCurrentTime = 0;
};

protected onManifestLoaded(
Expand Down
3 changes: 0 additions & 3 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ export default class StreamController

protected onTickEnd() {
super.onTickEnd();
if (this.media?.readyState && this.media.seeking === false) {
this.lastCurrentTime = this.media.currentTime;
}
this.checkFragmentChanged();
}

Expand Down
10 changes: 9 additions & 1 deletion tests/unit/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,22 @@ describe('BaseStreamController', function () {

describe('Seeking Logic', function () {
describe('onMediaSeeking', function () {
it('should handle backward seek behavior correctly', function () {
it('should handle backward seek after media buffered behavior correctly', function () {
// Mock hasEnoughToStart to return false:
// lastCurrentTime is updated with startPosition and nextLoadPosition before start
const hasEnoughToStartStub = sinon
.stub(baseStreamController.hls, 'hasEnoughToStart')
.get(() => true);

// Setup initial state for backward seek
baseStreamController.lastCurrentTime = 10.5;
media.currentTime = 5.2;

// Call onMediaSeeking - should execute without error
expect(() => baseStreamController.onMediaSeeking()).to.not.throw();

hasEnoughToStartStub.restore();

// Verify lastCurrentTime is not updated on backward seek
expect(baseStreamController.lastCurrentTime).to.equal(10.5);
});
Expand Down
Loading