我似乎无法找到MediaCapture类的属性,它允许我检测Surface中的后置和前置摄像头,如果Combobox Items可用,则切换到它。这是我当前设备的设置。
mc = new MediaCapture();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
// Use the front camera if found one
if (devices == null) return;
var info = devices[0];
//var rearCamera;
//DeviceInformation info2 = devices[1];
foreach (var devInfo in devices)
{
if (devInfo.Name.ToLowerInvariant().Contains("front"))
{
info = devInfo;
//info2 = devInfo;
//frontCam = true;
//backCam = true;
camera = true;
//continue;
}
if (devInfo.Name.ToLowerInvariant().Contains("back"))
{
var rearCamera = devices[1];
rearCamera = devInfo;
}
}
await mc.InitializeAsync(new MediaCaptureInitializationSettings
{
MediaCategory = MediaCategory.Communications,
StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
VideoDeviceId = info.Id,
//VideoDeviceId = info2.Id
});
DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();
displayInfo.OrientationChanged += DisplayInfo_OrientationChanged;
DisplayInfo_OrientationChanged(displayInfo, null);
stream = new InMemoryRandomAccessStream();
llmr = await mc.PrepareLowLagRecordToStreamAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), stream);
await llmr.StartAsync();
await llmr.StopAsync();
CaptureElement.Source = mc;
CaptureElement.FlowDirection = camera ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
CaptureStack.Visibility = Visibility.Visible;
CameraErrorTextBlock.Visibility = Visibility.Collapsed;
RecordProgress.Visibility = Visibility.Visible;
CaptureGrid.Visibility = Visibility.Visible;
CancelButton.HorizontalAlignment = HorizontalAlignment.Right;
//CaptureElement.FlowDirection = FlowDirection.LeftToRight;
// prepare low lag recording
stream = new InMemoryRandomAccessStream();
llmr = await mc.PrepareLowLagRecordToStreamAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), stream);
await mc.StartPreviewAsync();
答案 0 :(得分:3)
您需要使用所需相机设备的VideoDeviceId(从DeviceInformationCollection设备获取)再次运行MediaCapture.InitializeAsync。然后将CaptureElement.Source设置为新的MediaCapture。
for (char c : input.toCharArray()) { ... }
答案 1 :(得分:2)
您应该使用DeviceInformation的 " EnclosureLocation" 属性。
var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
// Get the desired camera by panel
DeviceInformation cameraDevice =
allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null &&
x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
Windows.Devices.Enumeration.Panel.Back 将成为后置摄像头的EnclosureLocation。