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
6 changes: 5 additions & 1 deletion src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,11 @@ export default class BaseStreamController
this.state = State.IDLE;
break;
}
this.nextLoadPosition = this.playhead;
// Before start, the playhead is the load position, which loading the aborted fragment
// moved to its end. Go back to the start position instead.
this.nextLoadPosition = this.hls?.hasEnoughToStart
? this.playhead
: this.lastCurrentTime;
}

protected checkFragPlaying(): boolean {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ describe('BaseStreamController', function () {
it('should update nextLoadPosition to current load position', function () {
baseStreamController.fragCurrent = mockFrag;
media.currentTime = 15;
baseStreamController.lastCurrentTime = 10;
baseStreamController.nextLoadPosition = 10;

(baseStreamController as any).abortCurrentFrag();
Expand Down
68 changes: 68 additions & 0 deletions tests/unit/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,5 +1180,73 @@ describe('StreamController', function () {
expect(streamController['fragCurrent']).to.be.null;
expect(streamController['state']).to.equal(State.IDLE);
});

describe('before anything is buffered', function () {
const loadLevel = (level: number, durations: number[]) => {
const details = M3U8Parser.parseLevelPlaylist(
`#EXTM3U
#EXT-X-TARGETDURATION:5
${durations.map((duration, i) => `#EXTINF:${duration},\n${i}.ts`).join('\n')}
#EXT-X-ENDLIST`,
`http://www.example.com/${level}.m3u8`,
level,
PlaylistLevelType.MAIN,
0,
null,
);
hls.trigger(Events.LEVEL_LOADED, {
details,
id: 0,
level,
networkDetails: new Response('ok'),
stats: new LoadStats(),
deliveryDirectives: null,
levelInfo: hls.levels[level],
});
};

beforeEach(function () {
loadManifest(`#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=400000
0.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=800000
1.m3u8`);
sinon
.stub(streamController['fragmentLoader'], 'load')
.callsFake((frag) => {
frag.loader = { abort() {}, destroy() {} } as any;
return new Promise(() => {});
});
streamController['media'] = streamController['mediaBuffer'] = {
buffered: new TimeRangesMock(),
currentTime: 0,
readyState: 0,
seeking: false,
} as any as HTMLMediaElement;
hls.startLevel = 1;
streamController.startLoad(8.09);
loadLevel(1, [4, 4, 4, 4, 4]);
expect(streamController['fragCurrent']).to.include({
level: 1,
start: 8,
});
});

it('should keep the playhead at the start position when the first fragment is aborted', function () {
streamController['abortCurrentFrag']();

expect(streamController['playhead']).to.equal(8.09);
});

it('should load the start position when a level switch aborts the first fragment', function () {
// Switch levels while the fragment containing the start position is loading
hls.loadLevel = 0;
loadLevel(0, [3, 3, 3, 3, 3, 3]);
expect(streamController['fragCurrent']).to.include({
level: 0,
start: 6,
});
});
});
});
});
Loading