My problem is quite simple, I cannot turn on the flash light with the MediaCapture API from windows phone 8.1. (I succedded with the 8.0 API)
I built a very simple project with 2 buttons, one to toggle the FlashControl and the other one to toggle TorchControl.
There is no crash, no exception. My phones support FlashControl and TorchControl. I also debug step-by-step and everything looks good, values are changed when buttons are clicked.
Here is my code:
MediaCapture m_captureManager;
public MainPage()
{
InitializeComponent();
}
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera {0} doesn't exist", desiredCamera));
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
m_captureManager = new MediaCapture();
await m_captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
}
private void button_ClickTorch(object sender, RoutedEventArgs e)
{
var torch = m_captureManager.VideoDeviceController.TorchControl;
if (torch.Supported)
{
if (torch.Enabled)
torch.Enabled = false;
else
torch.Enabled = true;
}
}
private void button_ClickFlash(object sender, RoutedEventArgs e)
{
if (captureManager.VideoDeviceController.FlashControl.Supported)
{
if (captureManager.VideoDeviceController.FlashControl.Enabled)
captureManager.VideoDeviceController.FlashControl.Enabled = false;
else
captureManager.VideoDeviceController.FlashControl.Enabled = true;
}
}
It's a simple piece of code and I cannot make it works... I was quite desperate so I tried to toggle by using an intermediate object and without, as you can see, but it did not change the result (which is in conformity).