in Tools/Cam360/MainPage.xaml.cs [475:531]
private async Task InitializeCameraAsync()
{
try
{
Debug.WriteLine("InitializeCameraAsync");
if (_mediaCapture == null)
{
//retrieve all camera sources on the system
IReadOnlyList<MediaFrameSourceGroup> allGroups = await MediaFrameSourceGroup.FindAllAsync();
List<MediaFrameSourceGroup> allGroupsList = allGroups.ToList();
string audioDeviceSelectorString = MediaDevice.GetAudioCaptureSelector();
// list all sources for debugging
foreach (var sourceGroup in allGroupsList)
{
Debug.WriteLine($"{ sourceGroup.DisplayName}");
List<MediaFrameSourceInfo> sourceInfo = sourceGroup.SourceInfos.ToList();
var names = Enum.GetNames(typeof(MediaFrameSourceKind));
var streamTypes = Enum.GetNames(typeof(MediaStreamType));
foreach (var info in sourceInfo)
{
Debug.WriteLine($" {info.DeviceInformation.Name} ---- { names[(int)info.SourceKind]} -- {streamTypes[(int)info.MediaStreamType]}");
}
}
//select only the sources which have have a color (non-IR/non-depth) video preview or video record stream
_mediaFrameSourceGroupList = allGroupsList.Where(group => group.SourceInfos.Any(sourceInfo => sourceInfo.SourceKind == MediaFrameSourceKind.Color
&& (sourceInfo.MediaStreamType == MediaStreamType.VideoPreview
|| sourceInfo.MediaStreamType == MediaStreamType.VideoRecord))).ToList();
// find all audio record sources.
_microphoneList = await DeviceInformation.FindAllAsync(audioDeviceSelectorString);
// retrieve all physical cameras device information.
_cameraList = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (_mediaFrameSourceGroupList.Count > 0)
{
// list all selectable sources into the drop down list for user
var cameraNamesList = _mediaFrameSourceGroupList.Select(group => group.DisplayName);
cmbCamera.ItemsSource = cameraNamesList;
cmbCamera.SelectedIndex = 0;
await EnableDisableCameraControlsOnUI(true);
}
else
{
string errorMessage = "No camera device found!";
Debug.WriteLine(errorMessage);
throw (new Exception(errorMessage));
}
}
}
catch (Exception ex)
{
TraceExceptionAsync(ex);
}
}