Skip to content

Commit

Permalink
Fix: Load the last remaining segment when the user seeks to end (#3847)
Browse files Browse the repository at this point in the history
* Fix: Load the last remaining segment when the user seeks to the very end of the timeline: currentTime = duration

* Return NaN in getContinuousBufferTimeForTargetTime if adjustedTime is equal to targetTime
  • Loading branch information
dsilhavy authored Jan 7, 2022
1 parent 89a296c commit 0f4196e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/streaming/StreamProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,14 @@ function StreamProcessor(config) {
})
.then(() => {
// Figure out the correct segment request time.
const targetTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime);
const continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime);

// If the buffer is continuous and exceeds the duration of the period we are still done buffering. We need to trigger the buffering completed event in order to start prebuffering upcoming periods again
if (!isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && targetTime >= streamInfo.start + streamInfo.duration) {
if (!isNaN(continuousBufferTime) && !isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && continuousBufferTime >= streamInfo.start + streamInfo.duration) {
bufferController.setIsBufferingCompleted(true);
resolve();
} else {
const targetTime = isNaN(continuousBufferTime) ? e.seekTime : continuousBufferTime;
setExplicitBufferingTime(targetTime);
bufferController.setSeekTarget(targetTime);

Expand Down Expand Up @@ -1085,7 +1086,8 @@ function StreamProcessor(config) {

function _bufferClearedForNonReplacement() {
const time = playbackController.getTime();
const targetTime = bufferController.getContinuousBufferTimeForTargetTime(time);
const continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(time);
const targetTime = isNaN(continuousBufferTime) ? time : continuousBufferTime;

setExplicitBufferingTime(targetTime);
scheduleController.startScheduleTimer();
Expand Down
4 changes: 2 additions & 2 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ function BufferController(config) {
const ranges = sourceBufferSink.getAllBufferRanges();

if (!ranges || ranges.length === 0) {
return targetTime;
return NaN;
}

let i = 0;
Expand All @@ -989,7 +989,7 @@ function BufferController(config) {
i += 1;
}

return adjustedTime;
return adjustedTime === targetTime ? NaN : adjustedTime;

} catch (e) {

Expand Down

0 comments on commit 0f4196e

Please sign in to comment.