Windows 8如何选择要初始化的摄像头 [英] Windows 8 how to choose which camera to initialize
问题描述
我正在开发 Windows商店应用程式
,我正在使用相机
和麦克风
功能。我想要的后置摄像头被初始化,但我发现的例子总是初始化前置摄像头。这里是我有的代码:
I am developing a Windows Store App
and I am using the Camera
and Microphone
capabilities. I would like the back camera to be initialized but the examples that I have found always initialize the front camera. Here's the code that I have:
Windows.Devices.Enumeration.DeviceInformation.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture)
.done(function (devices) {
if (devices.length > 0) {
// Using Windows.Media.Capture.MediaCapture APIs to stream from webcam
mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
mediaCaptureMgr.initializeAsync().done(initializeComplete, initializeError);
} else {
var div = document.createElement('div');
div.innerHTML = "No Camera found";
document.body.appendChild(div);
}
});
在这种情况下, mediaCaptureMgr
相机。我经历了文档,它说,我已经提供 videoDeviceId
到 MediaCapture()
函数像这样: / p>
In this case mediaCaptureMgr
refers to the front camera. I went through the documentation and it says that I have provide a videoDeviceId
to the MediaCapture()
function like this:
mediaCaptureMgr = new Windows.Media.Capture.MediaCapture({
videoDeviceId: devices[1].id
});
但是前置摄像头仍会初始化。我在Surface上编写和测试这个。
However still the front camera is initialized. I am writing and testing this on a Surface. Could you help me with this?
推荐答案
您必须创建一个 MediaCaptureInitializationSettings
object: p>
You have to create a MediaCaptureInitializationSettings
object:
var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
settings.videoDeviceId = devices[1].id;
mediaCaptureMgr.initializeAsync(settings).done(initializeComplete, initializeError);
这篇关于Windows 8如何选择要初始化的摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!