Skip to content

Commit

Permalink
feat: add buffered cache (#43)
Browse files Browse the repository at this point in the history
* feat: add buffered cache
  • Loading branch information
xiaoyuhen authored Mar 27, 2019
1 parent 9c5497c commit c7a7b2a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/dist
**/es
**/esm
**/cjs
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package-lock.json
lerna.json
CHANGELOG.md
**/dist
**/es
**/esm
**/cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build": "yarn build:lib && yarn build:standalone",
"build:watch": "lerna run build:watch --stream --parallel",
"release": "yarn build && lerna publish",
"start": "yarn workspace example run start"
"start": "npm run build:watch & yarn workspace example run start"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
Expand Down
22 changes: 22 additions & 0 deletions packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,33 @@ export default class MSE {
})
}

hasBufferedCache = (time = 0) => {
const buffered = this.video.buffered

if (buffered) {
for (let i = 0; i < buffered.length; i++) {
if (time >= buffered.start(i) && time <= buffered.end(i)) {
return true
}
}
}

return false
}

seek = time => {
FragmentFetch.clear()

const [start, end] = this.mp4Probe.getFragmentPosition(time)
this.mseUpdating = true

// 对于已经请求的数据不再重复请求
// No need to repeat request video data
const timeRange = this.mp4Probe.timeRange || []
if (this.hasBufferedCache(timeRange[1])) {
return
}

this.loadData(start, end).then(mdatBuffer => {
if (!mdatBuffer) {
return
Expand Down

0 comments on commit c7a7b2a

Please sign in to comment.