WebRTC - 浏览器不要求本地 html 文件的麦克风访问权限 [英] WebRTC - Browser doesn't ask for mic access permission for local html file

查看:43
本文介绍了WebRTC - 浏览器不要求本地 html 文件的麦克风访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的 webRTC 代码,它使用 getUserMedia 来访问用户的麦克风.现在,当我在浏览器中加载该 html 文件(保存在我的本地主机中)时,浏览器不会要求麦克风访问权限,因此无法访问.

I have some simple webRTC code which uses getUserMedia to gain access to user's mic. Now when I load that html file (saved at my localhost) in my browser, the browser doesn't ask for mic access permission and thus get failed to get access.

但是当我在 w3schools.com 编辑器中运行相同的 html 时,它要求麦克风访问权限,并在允许它访问我的麦克风时,它工作正常...

But when I run the same html inside the w3schools.com editor, it asks for mic access permission and upon allowing it to access my mic, it works fine...

为什么会有这种奇怪的行为?

Why is this strange behaviour?

推荐答案

当您直接从文件系统(file://前缀)打开 html 文件时,Chrome 将自动阻止 getUserMedia 权限.您必须在本地运行服务器.

When you open an html file right off the filesystem (file:// prefix), Chrome will auto-block getUserMedia permissions. You have to run a server locally.

我像这样启动了一个 sinatra 服务器:

I started up a sinatra server like this:

# server.rb
require 'sinatra'

get '/' do
  File.read('index.html')
end

那就早点给吧.

$ gem install sinatra
$ ruby server.rb

http://localhost:4567

这篇关于WebRTC - 浏览器不要求本地 html 文件的麦克风访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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