我有一个应用程序,可以打开我的网站的 web 视图。本网站打开后置摄像头拍照。我可以在那里完成它,但默认情况下,选择的相机不是首选相机。在我的三星S10中,打开的摄像头是广角,很不方便。
我怎样才能选择最好的相机?有人知道解决方法吗?
在桌面或移动 chrome 中,我在执行时得到标签,navigator.mediaDevices.enumerateDevices()
但在 webview 中是空的。
这是我的 webrtc 函数:
await this.stopTracksCamera();
let idealDevideId = undefined;
await navigator.mediaDevices.getUserMedia({ video: true }).then(async stream => {
this.tempStream = stream;
});
idealDevideId = await this.scanDevices();
await this.stopTracksCamera();
await navigator.mediaDevices.getUserMedia(constraints).then(stream => {
this.videoDom.srcObject = stream;
...
还有我的应用 webview 设置:
WebView web = (WebView) findViewById(R.id.silt_web);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
web.setWebContentsDebuggingEnabled(true);
}
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webSettings.setMediaPlaybackRequiresUserGesture(false);
}
web.setWebViewClient(new WebViewClient());
web.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(final PermissionRequest request) {
Log.d(TAG, "onPermissionRequest");
MainActivity.this.runOnUiThread(new Runnable() {
@TargetApi(Build.VERSION_CODES.M)
@Override
public void run() {
Log.d(TAG, request.getOrigin().toString());
/*if(request.getOrigin().toString().equals("file:///")) {*/
Log.d(TAG, "GRANTED");
request.grant(request.getResources());
/*} else {
Log.d(TAG, "DENIED");
request.deny();
}*/
}
});
}
...