我正处在这个错误的临界点。我开发了一个带有hls.js
视频播放器的svelte网络应用程序,我把它打包到了一个安卓网络视图中,用于显示萤火虫。该应用程序工作很好,除了一个奇怪的问题,在大约3-4个小时的播放后,视频冻结。我能够使用adb
捕获一些日志。
错误并不发生在通常的hls.js
onError
处理程序中,而是在其他地方生成。Cannot read properties of null (reading 'byteLength')
是完全模棱两可的,但它是我所能得到的最好的。不幸的是,错误只发生在实际的精简JS代码上,而不发生在任何浏览器调试版本上.。
我完全不知道是什么原因造成的,甚至是如何调试它。也许有人在过去经历过这样的事情?下面是我的svelte组件中的视频元素和hls.js
初始化代码。
<div class="playback-view" on:click|stopPropagation>
<video
bind:this={videoRef}
bind:currentTime={$ProgramTime}
on:ended={onPlaybackEnded}
bind:duration
bind:paused>
<track kind="captions">
</video>
const destroyHls = () => {
if (hls !== null && hls !== undefined){
hls.stopLoad()
hls.detachMedia()
hls.destroy()
}
}
const reloadSource = () => {
destroyHls()
if (videoRef !== null && videoRef !== undefined){
hls = new Hls({
// Audio codec for bitrate above 22hz
defaultAudioCodec: "mp4a.40.2",
//(seconds) If buffer < this value fragment will be loaded
// The "minimum" length of the buffer
maxBufferLength: 15,
backBufferLength: 1800,
// (seconds) The maximum length of the buffer
maxMaxBufferLength: 60,
// (bytes) The amount hls will try to load
// maxBufferSize: 120 * 1000 * 1000,
// (seconds) The amount to offset the stream by when stalling
// currentTime += (nb nudge retry -1)*nudgeOffset
nudgeOffset: 0.1,
// Number of nudges before BUFFER_STALLED_ERROR
nudgeMaxRetry: 3,
})
hls.attachMedia(videoRef)
hls.loadSource($Playback.playbackUrl)
hls.on(Hls.Events.ERROR, handleHLSError)
videoRef.play()
paused = false
}
}
在建议检查缓冲区大小之后。我降低了backBufferLength和maxMaxBufferLength。然而,现在我面临一个新的错误。
"hlsError" {"type":"mediaError","parent":"main","details":"bufferAppendError","err":{"stack":"Error: Failed to execute 'appendBuffer' on 'SourceBuffer': The HTMLMediaElement.error attribute is not null.
这没有添加到源缓冲区,但是hls.js
不应该负责清除缓冲区吗?
发布于 2022-08-17 11:41:06
不幸的是,我无法为这个问题找出一组持续工作的设置。更改HLS选项只会导致不同的错误发生。最后,我基本上做了一些与@VC.One建议类似的事情。
我使用hls.js
的hls.js
方法来检测fragLoadError
,当它出现时,我会在特定的时间重新加载流。这意味着按照原始问题中的定义调用reloadSource
。
我不觉得这个解决方案令人惊讶,因为它只是一个绷带,但它的工作相当可靠。最多每隔几个小时你就会在视频播放中被冻结5秒钟。
https://stackoverflow.com/questions/73271339
复制相似问题