Skip to content

Commit

Permalink
fix: cannot read property start of undefined (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored Apr 25, 2019
1 parent a392a72 commit 9e2740a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/griffith-mp4/src/mp4/mp4Probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ export default class MP4Probe {

const {videoSamples, audioSamples} = this.getSamples()
const stcoBox = findBox(this.mp4BoxTree, 'videoStco')

let videoSamplesStart = 0
if (videoSamples.length > 0) {
videoSamplesStart = videoSamples[videoSamples.length - 1].start
}
const isLastFragmentPosition =
videoSamples[videoSamples.length - 1].start +
videoSamples[videoSamples.length - 1].bufferStart ===
videoSamplesStart + videoSamples[videoSamples.length - 1].bufferStart ===
stcoBox.samples[stcoBox.samples.length - 1].chunkOffset

return getFragmentPosition(
Expand Down
6 changes: 5 additions & 1 deletion packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export default function getFragmentPosition(
isLastFragmentPosition
) {
const videoSamplesEnd = videoSamples[videoSamples.length - 1].end
const videoSamplesStart = videoSamples[0].start
let videoSamplesStart = 0

if (videoSamples.length > 0) {
videoSamplesStart = videoSamples[0].start
}

// maybe the last GOP dont have audio track
// 最后一个 GOP 序列可能没有音频轨
Expand Down
10 changes: 8 additions & 2 deletions packages/griffith-mp4/src/mse/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class MSE {
}
} catch (error) {
// see https://developers.google.com/web/updates/2017/10/quotaexceedederror
if (error.name === 'QuotaExceededError') {
if (error.code === 22) {
this.handleQuotaExceededError(buffer, type)
} else {
throw error
Expand Down Expand Up @@ -313,7 +313,13 @@ export default class MSE {
const track = this.sourceBuffers[key]

const currentTime = this.video.currentTime
this.removeBuffer(track.buffered.start(0) + 10, currentTime - 10, key)

let removeStart = 0

if (track.buffered.length > 0) {
removeStart = track.buffered.start(0) + 10
}
this.removeBuffer(removeStart, currentTime - 10, key)
}

// re-append(maybe should lower the playback resolution)
Expand Down
6 changes: 5 additions & 1 deletion packages/griffith-mp4/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export default class Player extends Component {
// 如果当前时间为 0,safari 浏览器需要把 currentTime 设置成 buffered.start(0) 右边一点点的位置
// 否则 MSE 无法正常播放,会卡在 loading 状态。
handleSafariBug = () => {
const start = this.video.buffered.start(0)
let start = 0

if (this.video.buffered.length > 0) {
start = this.video.buffered.start(0)
}
this.video.currentTime = start + 0.1
}

Expand Down

0 comments on commit 9e2740a

Please sign in to comment.