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

fix: failed to execute appendBuffer on SourceBuffer #68

Merged
merged 2 commits into from
Apr 16, 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
1 change: 1 addition & 0 deletions packages/griffith-mp4/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class FragmentFetch {
xhr.responseType = 'arraybuffer'
xhr.setRequestHeader('Range', `bytes=${start}-${end}`)
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, OPTIONS')
xhr.setRequestHeader('Access-Control-Allow-Origin', '*')
xhr.onload = () => {
if (xhr.status === 200 || xhr.status === 206) {
callback(xhr.response)
Expand Down
22 changes: 12 additions & 10 deletions packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ export default class MSE {
})
}

hasBufferedCache = (time = 0) => {
hasBufferedCache = isSeek => {
const {
timeRange: [start, end],
} = this.mp4Probe

// handle seek case and normal case
const time = isSeek ? this.video.currentTime : Math.floor((start + end) / 2)
const buffered = this.video.buffered

if (buffered) {
Expand All @@ -149,16 +155,12 @@ export default class MSE {
FragmentFetch.clear()

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

// 对于已经请求的数据不再重复请求
// No need to repeat request video data
if (
time &&
this.hasBufferedCache(this.video.currentTime) &&
!this.qualityChangeFlag
) {
if (this.hasBufferedCache(time) && !this.qualityChangeFlag) {
return
}

this.handleReplayCase()

this.loadData(start, end).then(mdatBuffer => {
Expand Down Expand Up @@ -231,7 +233,6 @@ export default class MSE {
videoInterval: {offsetInterVal = []} = [],
mp4Data: {videoSamplesLength},
} = this.mp4Probe

if (this.mediaSource.readyState !== 'closed') {
if (offsetInterVal[1] === videoSamplesLength) {
this.destroy()
Expand All @@ -243,13 +244,14 @@ export default class MSE {

handleReplayCase = () => {
if (this.mediaSource.readyState === 'ended') {
this.sourceBuffers.video.appendBuffer(new Uint8Array(0))
// If MediaSource.readyState value is ended,
// setting SourceBuffer.timestampOffset will cause this value to transition to open.
this.sourceBuffers.video.timestampOffset = 0
}
}

shouldFetchNextSegment = () => {
this.handleReplayCase()

if (this.mp4Probe.isDraining(this.video.currentTime)) {
return true
}
Expand Down