-api-id | -api-type |
---|---|
M:Windows.Media.Devices.VideoDeviceController.TryAcquireExclusiveControl(System.String,Windows.Media.Capture.MediaCaptureDeviceExclusiveControlReleaseMode) |
winrt method |
Windows.Media.Devices.VideoDeviceController.TryAcquireExclusiveControl(System.String,Windows.Media.Capture.MediaCaptureDeviceExclusiveControlReleaseMode)
Requests exclusive control of the camera with the specified device ID.
The device ID of the camera for which exclusive control is requested. The device ID can be obtained with the DeviceInformation class.
A value from the MediaCaptureDeviceExclusiveControlReleaseMode enumeration specifying the conditions under which exclusive control is released.
True if exclusive control of the camera was acquired; otherwise, false.
This example demonstrates how an application using camera in exclusive control can ensure that camera configuration is set before start of capture and will not be altered by another application that has access to this camera by acquiring the exclusive control lock ahead of it.
private static System.Threading.ManualResetEvent _exclusiveLockAcquire = new System.Threading.ManualResetEvent(false);
public static void RecordVideo()
{
MediaCapture mediacapture = new MediaCapture();
await mediacapture.InitializeAsync();
mediacapture.CaptureDeviceExclusiveControlStatusChanged +=
Mediacapture_CaptureDeviceExclusiveControlStatusChanged;
_exclusiveLockAcquire.WaitOne();
_exclusiveLockAcquire.Reset();
// configure camera - blocking other application from changing the configuration.
// record video
}
private static void Mediacapture_CaptureDeviceExclusiveControlStatusChanged(MediaCapture sender, MediaCaptureDeviceExclusiveControlStatusChangedEventArgs args)
{
if (args.Status == MediaCaptureDeviceExclusiveControlStatus.ExclusiveControlAvailable)
{
if (sender.VideoDeviceController().TryAcquireExclusiveControl(
args.DeviceId(),
MediaCaptureDeviceExclusiveControlReleaseMode.OnAllStreamsStopped))
{
_exclusiveLockAcquire.Set();
}
}
}