尽管是adapter.js,GetUserMedia - facingMode仍然无法识别 [英] GetUserMedia - facingMode not recognized despite adapter.js
问题描述
我想在离子应用程序中获取后置摄像头的视频流。
为此,我使用可正常用于前置摄像头的getUserMedia。
I want to get the video stream of my rear camera in an Ionic Application. For this, I use getUserMedia that work correctly for the front camera.
当我将面向模式更改为环境时,我收到此错误:
When I change the facing mode to 'environment' I got this error :
名为facingMode的未知约束被拒绝
ConstraintNotSatisfiedError
在我的Ionic应用程序中,我已经安装了npm软件包webrtc-adapter。
In my Ionic application I have already installed the npm package "webrtc-adapter".
这是我从后置摄像头获取流的代码:
Here is my code to get the stream from the rear camera :
this.constraints = { audio: true, video: {mandatory: { facingMode: 'environment'}}};
cordova.plugins.diagnostic.requestRuntimePermission( (status) => {
if (cordova.plugins.diagnostic.permissionStatus.GRANTED){
navigator.getUserMedia(this.constraints, (stream) => {
let video = <HTMLVideoElement>document.getElementById('localVideo');
video.srcObject = stream;
}, function(err){
console.log("Error get stream: ", err.name);
});
}
}, (error) => {
console.error("Error during runtime permission :", error);
}, cordova.plugins.diagnostic.permission.CAMERA);
我认为这是兼容性问题。有人可以帮帮我吗?
I think that is a compatibility issue. Anyone can help me ?
谢谢。
推荐答案
你'重新使用过时的非标准约束语法。 adapter.js 会填充规范,因此要从中受益,您必须关注规范。
例如而不是:
You're using an outdated non-standard constraints syntax. adapter.js polyfills the spec, so to benefit from it you have to follow the spec. E.g. instead of:
{audio: true, video: {mandatory: {facingMode: 'environment'}}};
使用
{audio: true, video: {facingMode: {exact: 'environment'}}};
我已经这是一个有效的例子的回答。它应该适用于Chrome。不确定这是否适用于离子。如果它不起作用,请告诉我。
I already have an answer with a working example of this. It should work with Chrome. Not sure if this will work with ionic or not. Let me know if it doesn't work.
这篇关于尽管是adapter.js,GetUserMedia - facingMode仍然无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!