【问题标题】:Failed to convert value to MediaStream无法将值转换为 MediaStream
【发布时间】:2022-11-21 13:38:13
【问题描述】:

我正在尝试实现 Screen Capture API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture#capturing_screen_contents

我在 React JS 中构建相同的代码,

当我放置以下代码时出现错误“无法在‘HTMLMediaElement’上设置‘srcObject’属性:无法将值转换为‘MediaStream’。”

<video id="video"></video>
video = document.getElementById("video");
video.srcObject = navigator.mediaDevices.getDisplayMedia(displayMediaOptions);```


Please someone help in resolving this issue

【问题讨论】:

  • 您是否尝试使用异步/等待:do video.srcObject = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions)
  • 你能分享整个代码吗,或者错误信息

标签: reactjs html5-video screenshot mediastream


【解决方案1】:

HTML

<video id="video"></video>

JS

video = document.getElementById("video");
 
async function startCapture() {
  

  try {
    video.srcObject = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
  } catch(err) {
    console.error("Error: " + err);
  }
  return captureStream;
}
startCapture()

【讨论】:

  • 工作我尝试没有异步和等待
猜你喜欢
  • 2018-11-21
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
  • 1970-01-01
相关资源
最近更新 更多