Skip to content

Commit 046c77e

Browse files
committed
FlvPlayer: Hit currentTime to beginPTS if seek to video begin to avoid re-download
1 parent f19eca9 commit 046c77e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/player/flv-player.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,21 @@ class FlvPlayer {
459459
_internalSeek(seconds) {
460460
let directSeek = this._isTimepointBuffered(seconds);
461461

462-
if (directSeek) { // buffered position
462+
let directSeekBegin = false;
463+
let directSeekBeginTime = 0;
464+
465+
if (seconds < 1.0) {
466+
let videoBeginTime = this._mediaElement.buffered.start(0);
467+
if (videoBeginTime < 1.0 && seconds < videoBeginTime) {
468+
directSeekBegin = true;
469+
directSeekBeginTime = videoBeginTime;
470+
}
471+
}
472+
473+
if (directSeekBegin) { // seek to video begin, set currentTime directly if beginPTS buffered
474+
this._requestSetTime = true;
475+
this._mediaElement.currentTime = directSeekBeginTime;
476+
} else if (directSeek) { // buffered position
463477
if (!this._alwaysSeekKeyframe) {
464478
this._requestSetTime = true;
465479
this._mediaElement.currentTime = seconds;
@@ -530,6 +544,16 @@ class FlvPlayer {
530544
this._requestSetTime = false;
531545
return;
532546
}
547+
548+
if (target < 1.0) { // seek to video begin, set currentTime directly if beginPTS buffered
549+
let videoBeginTime = this._mediaElement.buffered.start(0);
550+
if (videoBeginTime < 1.0 && target < videoBeginTime) {
551+
this._requestSetTime = true;
552+
this._mediaElement.currentTime = videoBeginTime;
553+
return;
554+
}
555+
}
556+
533557
if (this._isTimepointBuffered(target)) {
534558
if (this._alwaysSeekKeyframe) {
535559
let idr = this._msectl.getNearestKeyframe(Math.floor(target * 1000));

0 commit comments

Comments
 (0)