什么约束应该传递给getUserMedia(),以获得两个视频mediaStreamTracks? [英] What constraints should I pass to getUserMedia() in order to get two video mediaStreamTracks?

查看:2003
本文介绍了什么约束应该传递给getUserMedia(),以获得两个视频mediaStreamTracks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 navigator.mediaDevices.enumerateDevices()承诺获得videoinput类的mediaDevice。

I can get mediaDevices of 'videoinput' kind via navigator.mediaDevices.enumerateDevices() promise.

我可以通过 navigator.mediaDevices.getUserMedia(constraints) promise获得mediaStream。

I can get mediaStream via navigator.mediaDevices.getUserMedia(constraints) promise.

应该约束看起来像是为了在userMedia中有两个视频轨?

What should constraints look like in order to have two video tracks in userMedia?

推荐答案

每次调用 getUserMedia / code>,但你可以多次调用它。

You can get max one video track and one audio track each time you call getUserMedia(), but you can call it multiple times. This may ask the user more than once though, depending on https, browser, and what the user does.

按照标准(此时需要使用 adapter.js ),以获取特定的videoinput设备,将其 deviceId getUserMedia 使用 deviceId 约束:

Following the standard (which at this time requires using adapter.js in Chrome), to get a specific "videoinput" device, pass its deviceId into getUserMedia using the deviceId constraint:

navigator.mediaDevices.enumerateDevices()
.then(devices => {
  var camera = devices.find(device => device.kind == "videoinput");
  if (camera) {
    var constraints = { deviceId: { exact: camera.deviceId } };
    return navigator.mediaDevices.getUserMedia({ video: constraints });
  }
})
.then(stream => video.srcObject = stream)
.catch(e => console.error(e));

exact

如果你想要两台相机,你必须调用 getUserMedia 再次使用不同的 deviceId ,希望您所使用的操作系统支持它(例如手机一般不支持)。

If you want two cameras, you'll have to call getUserMedia again with a different deviceId, and hope the OS you're on supports it (e.g. phones generally don't).

这篇关于什么约束应该传递给getUserMedia(),以获得两个视频mediaStreamTracks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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