Example #1
0
 /// <summary>
 /// Create an IFrameSource from a source object. Currently supports Windows.Storage.StorageFile
 /// and Windows.Media.Capture.MediaCapture source objects.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static async Task <IFrameSource> CreateFrameSourceAsync(object source, EventHandler <string> failureHandler)
 {
     try
     {
         if (source is Windows.Storage.StorageFile)
         {
             var sourceFile = source as Windows.Storage.StorageFile;
             if (sourceFile.ContentType.StartsWith("image"))
             {
                 return(await ImageFileFrameSource.CreateFromStorageFileAsyncTask(sourceFile));
             }
             else if (sourceFile.ContentType.StartsWith("video"))
             {
                 return(await MediaPlayerFrameSource.CreateFromStorageFileAsyncTask(sourceFile, failureHandler));
             }
             else
             {
                 throw new ArgumentException("Invalid file type received: " + sourceFile.ContentType);
             }
         }
         else if (source is Windows.Devices.Enumeration.DeviceInformation)
         {
             return(await FrameReaderFrameSource.CreateFromVideoDeviceInformationAsync(source as Windows.Devices.Enumeration.DeviceInformation, failureHandler));
         }
         else
         {
             throw new ArgumentException();
         }
     }
     catch (Exception ex)
     {
         failureHandler(null, ex.Message);
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Static factory method
        /// </summary>
        /// <param name="videoDeviceInformation"></param>
        /// <param name="imageDescriptor"></param>
        /// <param name="failureHandler"></param>
        /// <returns></returns>
        public static async Task <FrameReaderFrameSource> CreateFromVideoDeviceInformationAsync(
            DeviceInformation videoDeviceInformation,
            ISkillFeatureImageDescriptor imageDescriptor,
            EventHandler <string> failureHandler)
        {
            // Create new MediaCapture connected to our device
            var result = new FrameReaderFrameSource()
            {
                m_mediaCapture                       = new MediaCapture(),
                m_desiredImageDescriptor             = imageDescriptor,
                m_failureHandler                     = failureHandler,
                m_mediaCaptureInitializationSettings = new MediaCaptureInitializationSettings
                {
                    SharingMode          = MediaCaptureSharingMode.ExclusiveControl,
                    MemoryPreference     = MediaCaptureMemoryPreference.Auto,
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    VideoDeviceId        = videoDeviceInformation.Id,
                }
            };

            result.m_mediaCapture.Failed += result.MediaCapture_Failed;

            await result.IntializeFrameSourceAsync();

            return(result);
        }