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: cannot read property start of undefined #86

Merged
merged 1 commit into from
Apr 25, 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
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