diff --git a/packages/griffith-mp4/src/mp4/mp4Probe.js b/packages/griffith-mp4/src/mp4/mp4Probe.js index e3905008..ea526770 100644 --- a/packages/griffith-mp4/src/mp4/mp4Probe.js +++ b/packages/griffith-mp4/src/mp4/mp4Probe.js @@ -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( diff --git a/packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js b/packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js index 6c7af64e..c816a42a 100644 --- a/packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js +++ b/packages/griffith-mp4/src/mp4/utils/getFragmentPosition.js @@ -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 序列可能没有音频轨 diff --git a/packages/griffith-mp4/src/mse/controller.js b/packages/griffith-mp4/src/mse/controller.js index 9862cbc6..12382681 100644 --- a/packages/griffith-mp4/src/mse/controller.js +++ b/packages/griffith-mp4/src/mse/controller.js @@ -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 @@ -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) diff --git a/packages/griffith-mp4/src/player.js b/packages/griffith-mp4/src/player.js index 55b088eb..c446dead 100644 --- a/packages/griffith-mp4/src/player.js +++ b/packages/griffith-mp4/src/player.js @@ -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 }