Skip to content

Commit

Permalink
feat(xgplayer): checkBuffer add startDiff options
Browse files Browse the repository at this point in the history
  • Loading branch information
xiong-001 authored and gemxx committed Apr 23, 2024
1 parent 8e1a45e commit 7163087
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/xgplayer/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2046,19 +2046,28 @@ class Player extends MediaProxy {
}

/**
*
* @param { number } time
* 目标时间点是否在buffer内
* @param { number } time 时间点
* @param options 判断阈值配置,可选的
* @param options.startDiff 判断起始阈值,即该时间下距离buffer开始点超过阈值时才算作在buffer内,默认为0
* @param options.endDiff 判断结束阈值,即该时间下距离buffer结束点超过阈值时才算作在buffer内,默认为0
* @returns { boolean }
*/
checkBuffer (time) {
checkBuffer (
time,
options = {
startDiff: 0,
endDiff: 0
}) {
const { startDiff = 0, endDiff = 0 } = options || {}
const buffered = this.media.buffered
if (!buffered || buffered.length === 0 || !this.duration) {
return true
}
const currentTime = time || this.media.currentTime || 0.2
const len = buffered.length
for (let i = 0; i < len; i++) {
if (buffered.start(i) <= currentTime && buffered.end(i) > currentTime) {
if (buffered.start(i) + startDiff <= currentTime && buffered.end(i) - endDiff > currentTime) {
return true
}
}
Expand Down

0 comments on commit 7163087

Please sign in to comment.