Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add buffered cache #43

Merged
merged 2 commits into from
Mar 27, 2019
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
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