从前置摄像头切换到后置摄像头JS [英] switch from front camera to back camera JS

查看:130
本文介绍了从前置摄像头切换到后置摄像头JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我糟糕的英语道歉。我有一个QR扫描相机,但当我在我的网站上用手机打开时,我的网站上的脸部相机开启了。但我想使用后置摄像头



如果有人可以帮助我。我将非常感激

  function setwebcam()
{

var constraints = { audio:true,video:true};




document.getElementById(result)。innerHTML = - scanning - ;
if(stype == 1)
{
setTimeout(captureToCanvas,500);
返回;
}
var n = navigator;
document.getElementById(outdiv)。innerHTML = vidhtml;
v = document.getElementById(v);

if(n.getUserMedia)
n.getUserMedia(constraints,success,error);
else
if(n.webkitGetUserMedia)
{
webkit = true;
n.webkitGetUserMedia(约束,成功,错误);
}
else
if(n.mozGetUserMedia)
{
moz = true;
n.mozGetUserMedia(约束,成功,错误);
}


解决方案

您可以使用 MediaStreamTrack.getSources(回调)获取所有媒体资源及其ID。使用其他属性,您可以过滤以检查音频视频或按名称过滤。一旦您知道要显示的媒体来源的ID,请使用它将其附加到视频标记。



这是一个很好的例子:

https://simpl.info/getusermedia/sources/

https://github.com/samdutton/simpl/blob/master/getusermedia/ sources / js / main.js


I apologize for my bad english. I have a QR scan camera but when I will open by cell phone in my website, the face camera turned on in my website. but I want to use the back camera

if someone can help me. I would be very grateful

function setwebcam()
{

 var constraints = { audio: true, video: true };




document.getElementById("result").innerHTML="- scanning -";
if(stype==1)
{
    setTimeout(captureToCanvas, 500);    
    return;
}
var n=navigator;
document.getElementById("outdiv").innerHTML = vidhtml;
v=document.getElementById("v");

if(n.getUserMedia)
    n.getUserMedia(constraints, success, error);
else
if(n.webkitGetUserMedia)
{
    webkit=true;
    n.webkitGetUserMedia(constraints, success, error);
}
else
if(n.mozGetUserMedia)
{
    moz=true;
    n.mozGetUserMedia(constraints, success, error);
}

解决方案

You can use MediaStreamTrack.getSources(callback) to get all media sources and their id's. With other properties you can filter to check is it audio video or filter by name. Once you know id of media source you want to show, use it to attach it to video tag.

This is good example:
https://simpl.info/getusermedia/sources/
https://github.com/samdutton/simpl/blob/master/getusermedia/sources/js/main.js

这篇关于从前置摄像头切换到后置摄像头JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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