in FamilyNotes/UserDetection/UserPresence.cs [181:226]
private async Task InitializeCameraAsync()
{
if (_mediaCapture == null)
{
// Create MediaCapture and its settings
_mediaCapture = new MediaCapture();
var Settings = new MediaCaptureInitializationSettings();
// If we are using the default device, get it
if (IsDefaultCapture)
{
// Attempt to get the front camera if one is available, but use any camera device if not
var CameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);
if (CameraDevice == null)
{
Debug.WriteLine("No camera device found!");
return;
}
// Set the global camera device id
CameraDeviceId = CameraDevice.Id;
}
// Set the VideoDeviceId for the settings
Settings.VideoDeviceId = CameraDeviceId;
// Initialize MediaCapture
try
{
await _mediaCapture.InitializeAsync(Settings);
_isInitialized = true;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("The app was denied access to the camera.");
}
// If initialization succeeded, start the preview
if (_isInitialized)
{
await StartPreviewAsync();
}
}
}