Skip to content

Commit

Permalink
fix: replay case (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored Apr 9, 2019
1 parent e295326 commit e2693ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export default class MSE {
return
}

this.handleReplayCase()

this.loadData(start, end).then(mdatBuffer => {
if (!mdatBuffer) {
return
Expand Down Expand Up @@ -200,7 +202,8 @@ export default class MSE {
videoInterval: {offsetInterVal = []} = [],
mp4Data: {videoSamplesLength},
} = this.mp4Probe
if (this.mediaSource.readyState === 'open') {

if (this.mediaSource.readyState !== 'closed') {
if (offsetInterVal[1] === videoSamplesLength && !this.mseUpdating) {
this.destroy()
} else if (this.shouldFetchNextSegment()) {
Expand All @@ -209,7 +212,15 @@ export default class MSE {
}
}

handleReplayCase = () => {
if (this.mediaSource.readyState === 'ended') {
this.sourceBuffers.video.appendBuffer(new Uint8Array(0))
}
}

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

if (!this.mseUpdating && this.mp4Probe.isDraining(this.video.currentTime)) {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/griffith-mp4/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default class Player extends Component {
}

handlePlay = e => {
const {currentTime, buffered = []} = this.video
if (currentTime === 0 && !buffered.length) {
const {currentTime} = this.video
if (currentTime === 0) {
this.mse.seek(0)
}

Expand Down

0 comments on commit e2693ad

Please sign in to comment.