Skip to content

Commit

Permalink
fix: failed to execute start on TimeRanges (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored Apr 17, 2019
1 parent 3702079 commit b59c4d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class MSE {
const time = isSeek ? this.video.currentTime : Math.floor((start + end) / 2)
const buffered = this.video.buffered

if (buffered) {
if (buffered && buffered.length > 0) {
for (let i = 0; i < buffered.length; i++) {
if (time >= buffered.start(i) && time <= buffered.end(i)) {
return true
Expand Down Expand Up @@ -213,7 +213,9 @@ export default class MSE {
const track = this.sourceBuffers[key]
const length = track.buffered.length

track.remove(track.buffered.start(0), track.buffered.end(length - 1))
if (length > 0) {
track.remove(track.buffered.start(0), track.buffered.end(length - 1))
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions packages/griffith-mp4/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class Player extends Component {
const currentTime = this.video.currentTime
const buffered = this.video.buffered

if (isSafari) {
if (isSafari && buffered && buffered.length > 0) {
if (currentTime - 0.1 > buffered.start(0)) {
this.mse.seek(this.video.currentTime)
} else if (currentTime < buffered.start(0)) {
Expand Down Expand Up @@ -57,7 +57,12 @@ export default class Player extends Component {
handleVideoProgress = e => {
const buffered = this.video.buffered
const currentTime = this.video.currentTime
if (isSafari && buffered.length > 0 && currentTime < buffered.start(0)) {
if (
isSafari &&
buffered &&
buffered.length > 0 &&
currentTime < buffered.start(0)
) {
this.handleVideoSeeking()
}
this.props.onProgress(e)
Expand Down

0 comments on commit b59c4d0

Please sign in to comment.