예제 #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)
 {
     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));
         }
         else
         {
             throw new ArgumentException("Invalid file type received: " + sourceFile.ContentType);
         }
     }
     else if (source is Windows.Media.Capture.MediaCapture)
     {
         return(await FrameReaderFrameSource.CreateFromMediaCaptureAsync(source as Windows.Media.Capture.MediaCapture));
     }
     else
     {
         throw new ArgumentException();
     }
 }
예제 #2
0
        /// <summary>
        /// Static factory
        /// </summary>
        /// <returns></returns>
        public static async Task <MediaPlayerFrameSource> CreateFromStorageFileAsyncTask(StorageFile storageFile)
        {
            var result = new MediaPlayerFrameSource();

            result.m_mediaPlayer        = new MediaPlayer();
            result.m_mediaPlayer.Source = MediaSource.CreateFromStorageFile(storageFile);
            result.m_mediaPlayer.IsVideoFrameServerEnabled = true;
            result.m_mediaPlayer.RealTimePlayback          = true;
            result.m_mediaPlayer.IsMuted                  = true;
            result.m_mediaPlayer.IsLoopingEnabled         = true;
            result.m_mediaPlayer.CommandManager.IsEnabled = false;

            result.m_mediaPlayer.MediaOpened += result.mediaPlayer_MediaOpened;
            result.m_mediaPlayer.MediaEnded  += result.mediaPlayer_MediaEnded;

            await Task.Run(() => result.m_frameSourceReadyEvent.WaitOne());

            return(result);
        }