Chrome扩展程序-如何间隔访问网络摄像头和音频? [英] Chrome Extension - How to access webcam and Audio at intervals?

查看:40
本文介绍了Chrome扩展程序-如何间隔访问网络摄像头和音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Chrome扩展程序,该扩展程序想与我的网络摄像头集成,以执行一些时髦的计算机视觉和音频ML任务.

I have a chrome extension I am using that I want to integrate with my webcam to do some funky computer vision and audio ML stuff.

通常我会喜欢这个,

音频

<audio id="player" controls></audio>
<script>
  const player = document.getElementById('player');

  const handleSuccess = function(stream) {
    if (window.URL) {
      player.srcObject = stream;
    } else {
      player.src = stream;
    }
  };

  navigator.mediaDevices.getUserMedia({ audio: true, video: false })
      .then(handleSuccess);
</script>

用于网络摄像头

<video autoplay></video>

<script>
const constraints = {
  video: true
};

const video = document.querySelector('video');

navigator.mediaDevices.getUserMedia(constraints).
  then((stream) => {video.srcObject = stream});
</script>

使用chrome扩展名,最好的方法是使用background.js文件-我正在努力寻找有关如何使用它的任何文档或信息.

With a chrome extension, would the best pathway be to use the background.js file - I am struggling to find any documentation or information about how I could do it with that.

提前谢谢!

推荐答案

您可以创建一个选项页(位于扩展目录中的HTML文件),并在那里一次授予摄像头/音频许可.之后,您可以直接在背景脚本

You can create an option page (HTML file which lives in extension directory) and have camera/audio permissions granted there once. after this, you can use these APIs directly in background scripts

这是示例.

这篇关于Chrome扩展程序-如何间隔访问网络摄像头和音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆