我似乎找不到MediaCapture类的属性,该属性使我可以在Surface中检测前后摄像头,并在组合框项目可用时切换到该属性。这是我当前对设备的设置。
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();
最佳答案
您需要使用所需摄像机设备(从DeviceInformationCollection设备获取)的VideoDeviceId再次运行MediaCapture.InitializeAsync。然后将CaptureElement.Source设置为新的MediaCapture。
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devices.Count > 0)
{
if (devices.Count >= 2)
{
var device = devices.FirstOrDefault(d => d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
}
}
var frontVideoId = device.Id;
await mc.InitializeAsync(new MediaCaptureInitializationSettings
{
MediaCategory = MediaCategory.Communications,
StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
VideoDeviceId = frontVideoId
});
CaptureElement.Source = mc;
await mc.StartPreviewAsync();