Exemplo n.º 1
0
        public IAsyncOperation <AudioFrameReader> OpenAudioFrameReaderAsync()
        {
            return(Task.Run(async() =>
            {
                if (AudioReader == null)
                {
                    var microphones = await DeviceInformation.FindAllAsync(DeviceInformation.GetAqsFilterFromDeviceClass(DeviceClass.AudioCapture));
                    var kinectMicArray = microphones.FirstOrDefault(mic => mic.Name.ToLowerInvariant().Contains("xbox nui sensor"));

                    if (kinectMicArray != null)
                    {
                        //TODO: review parameters
                        var settings = new AudioGraphSettings(AudioRenderCategory.Speech);
                        settings.EncodingProperties = AudioEncodingProperties.CreatePcm(16000, 4, 32);
                        settings.EncodingProperties.Subtype = MediaEncodingSubtypes.Float;
                        settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency;
                        settings.DesiredRenderDeviceAudioProcessing = Windows.Media.AudioProcessing.Raw;

                        var audioGraphResult = await AudioGraph.CreateAsync(settings);
                        if (audioGraphResult.Status == AudioGraphCreationStatus.Success)
                        {
                            var inputNodeResult = await audioGraphResult.Graph.CreateDeviceInputNodeAsync(MediaCategory.Speech, audioGraphResult.Graph.EncodingProperties, kinectMicArray);

                            if (inputNodeResult.Status == AudioDeviceNodeCreationStatus.Success)
                            {
                                var output = audioGraphResult.Graph.CreateFrameOutputNode(audioGraphResult.Graph.EncodingProperties);
                                AudioReader = new AudioFrameReader(audioGraphResult.Graph, output);
                            }
                        }
                    }
                }
                AudioReader?.Open();
                return AudioReader;
            }).AsAsyncOperation());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether the device supports smart card reader mode
        /// </summary>
        /// <returns>None</returns>
        public static async Task <DeviceInformation> GetFirstSmartCardReaderInfo(SmartCardReaderKind readerKind = SmartCardReaderKind.Any)
        {
            // Check if the SmartCardConnection API exists on this currently running SKU of Windows
            if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardConnection"))
            {
                // This SKU of Windows does not support NFC card reading, only desktop and phones/mobile devices support NFC card reading
                return(null);
            }

            // Device selector string is from SmartCardReader.GetDeviceSelector(SmartCardReaderKind.Nfc) except that we remove the conditional
            // about the interface being enabled, since we want to get the device object regardless of whether the user turned it off in the CPL
            string query = "System.Devices.InterfaceClassGuid:=\"{DEEBE6AD-9E01-47E2-A3B2-A66AA2C036C9}\"";
            //if (readerKind != SmartCardReaderKind.Any)
            //{
            //    query += " AND System.Devices.SmartCards.ReaderKind:=" + (int)readerKind;
            //}

            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(query);

            if (devices.Count == 0)
            {
                devices = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{9a2fc585-7316-46f1-9577-500920304f9d}\"");
            }
            // There is a bug on some devices that were updated to WP8.1 where an NFC SmartCardReader is
            // enumerated despite that the device does not support it. As a workaround, we can do an additonal check
            // to ensure the device truly does support it.
            var workaroundDetect = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{50DD5230-BA8A-11D1-BF5D-0000F805F530}\"");

            if (workaroundDetect.Count == 0 || devices.Count == 0)
            {
                // Not supported
                if (readerKind == SmartCardReaderKind.Any)
                {
                    query            = DeviceInformation.GetAqsFilterFromDeviceClass(DeviceClass.ImageScanner);
                    workaroundDetect = await DeviceInformation.FindAllAsync(query);

                    if (workaroundDetect.Count == 0)
                    {
                        workaroundDetect = await DeviceInformation.FindAllAsync();

                        if (workaroundDetect.Count == 0)
                        {
                            return(null);
                        }
                        foreach (var item in workaroundDetect)
                        {
                            if (item.Name.ToLower().Contains("NPX".ToLower()) ||
                                item.Name.ToLower().Contains("Proximity".ToLower()) ||
                                item.Name.ToLower().Contains("Near".ToLower()))
                            {
                                return((from d in workaroundDetect
                                        where d.IsEnabled
                                        orderby d.IsDefault descending
                                        select d).FirstOrDefault());
                            }
                        }
                    }
                    ;
                }
            }
            else if (devices.Count == 0 && workaroundDetect.Count > 0)
            {
                devices = workaroundDetect;
            }
            // Smart card reader supported, but may be disabled
            return((from d in devices
                    where d.IsEnabled
                    orderby d.IsDefault descending
                    select d).FirstOrDefault());
        }