Mediarecorder“ onstop”活动在野生动物园两次发射

发布于 2025-01-23 01:08:52 字数 654 浏览 3 评论 0原文

在我的应用程序中,我正在使用Mediarecorder从用户录制一个简短的视频(最多30秒),然后将其发送到后端。为了检测录制已经停止,我使用了Mediarecorder的“ onStop”事件,在回调中,我构建了一个视频文件并调用上传过程。在Chrome和Edge中,它可以正常工作。该事件仅调用一次,但是在野生动物园中,我看到了不同的行为,“ onstop” “ ondataavailable” 事件两次调用。因此,我的逻辑被打破了,后端收到两个视频文件,第一个文件通常被打破,第二个是可以的。

this.mediaRecorder = new MediaRecorder(stream, {
  mimeType,
  videoBitsPerSecond,
});

this.mediaRecorder.addEventListener('dataavailable', () => {
  console.debug('dataavailable');
});

this.mediaRecorder.addEventListener('stop', () => {
  console.debug('stop');
});

this.mediaRecorder.start();
console.debug('start');

这是野生动物园还是正常行为的错误?

In my app, I'm using MediaRecorder to record a short video (up to 30s) from a user and then send it to the backend. To detect that recording has stopped, I use "onstop" event of MediaRecorder and in its callback I construct a video file and invoke uploading process. In Chrome and Edge it works fine. The event invokes only once, but in Safari I see different behavior, the "onstop" and "ondataavailable" events invoke twice. Therefore, my logic is broken, the backend receives two video files, the first one is broken usually, the second one is ok.

this.mediaRecorder = new MediaRecorder(stream, {
  mimeType,
  videoBitsPerSecond,
});

this.mediaRecorder.addEventListener('dataavailable', () => {
  console.debug('dataavailable');
});

this.mediaRecorder.addEventListener('stop', () => {
  console.debug('stop');
});

this.mediaRecorder.start();
console.debug('start');

Is this a bug of Safari or normal behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文