Javascript Windows 8如何选择要初始化的相机
我正在开发一个Windows应用商店应用程序,我正在使用摄像头和麦克风功能。我想初始化后摄像头,但我发现的示例总是初始化前摄像头。以下是我的代码:Javascript Windows 8如何选择要初始化的相机,javascript,windows-8,camera,winjs,Javascript,Windows 8,Camera,Winjs,我正在开发一个Windows应用商店应用程序,我正在使用摄像头和麦克风功能。我想初始化后摄像头,但我发现的示例总是初始化前摄像头。以下是我的代码: Windows.Devices.Enumeration.DeviceInformation.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture) .done(function (devices) { if (devices.length >
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指的是前置摄像头。我浏览了文档,它说我已经为MediaCapture功能提供了一个videoDeviceId,如下所示:
mediaCaptureMgr = new Windows.Media.Capture.MediaCapture({
videoDeviceId: devices[1].id
});
但是,前摄像头仍处于初始化状态。我正在表面上写和测试这个。你能帮我吗?你必须创建一个对象:
您必须创建一个对象:
仅为了完成正确答案,设备[1]并非始终是Surface以外设备上的后摄像头。 要测试相机和其他设备的放置位置,您必须检查设备信息是否包含本文中报告的其他重要信息: 完整的代码应该如下所示
if (devices.length > 0) {
devices.forEach(function (currDev) {
if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == Windows.Devices.Enumeration.Panel.back) {
defaultDeviceId = currDev.id;
}
})
}
仅为了完成正确答案,设备[1]并非始终是Surface以外设备上的后摄像头。 要测试相机和其他设备的放置位置,您必须检查设备信息是否包含本文中报告的其他重要信息: 完整的代码应该如下所示
if (devices.length > 0) {
devices.forEach(function (currDev) {
if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == Windows.Devices.Enumeration.Panel.back) {
defaultDeviceId = currDev.id;
}
})
}