Search code examples
c#video-capturewindows-8.1

Using Windows 8 API, (VideoCaptureDevices) in C# Console App


did a lot of looking around and I couldn't find any solution.

  • Goal: To blink the Camera flash LED on my Windows 8.1 tablet. Using Windows 8.1 to develop and VS2013.
  • The InitializeAsync method allows the application to initialize the Camera and Microphone with the default settings
  • I built the app as a Windows Store application and it worked flawlessly.
  • I need the file to be an executable and I need to convert it to a console application
  • I get the following error when I do mc.InitializeAsync "Error 1 'await' requires that the type 'Windows.Foundation.IAsyncAction' have a suitable GetAwaiter method. Are you missing a using directive for 'System'? c:\users\levi\documents\visual studio 2013\projects\ledblinkerconsole\ledblinkerconsole\torch.cs 16 14 LEDBlinkerConsole
  • I have no idea how to initialize the camera via a Console application
  • Any other ways to blink the LED flash are greatly appreciated. I do not have access to the memory locations though to do it in C++.

Thanks guys!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Media.Devices;
using Windows.Media.Capture;

namespace LEDBlinkerConsole
{
    class Torch
    {
        public async static void BlinkLED()
        {
            MediaCapture mc = new MediaCapture();
            await mc.InitializeAsync();

            Console.WriteLine("Please type \"flash\" to flash the LED\n");
            string consInput = Console.ReadLine();

            if (consInput.ToUpper() == "FLASH")
            {
                if (mc.VideoDeviceController.TorchControl.Supported == true)
                {
                    mc.VideoDeviceController.TorchControl.Enabled = true;
                    mc.VideoDeviceController.TorchControl.PowerPercent = 100;
                }
            }
        }
    }
}

Solution

  • I figured it out. I referenced "System.Runtime" and I had to reference "System.Runtime.Windowsruntime". I had to delete the reference to "System.Runtime" in order for it to work. More info here about the Async calls from a non-metro app: http://www.wintellect.com/blogs/jeffreyr/using-the-windows-runtime-from-a-non-metro-application