Discovering Devices
Discovering Media Devices
The very first step in using media devices is to discover available devices. To do so, you will use the MediaDeviceQuery
.
Querying for Devices
The MediaDeviceQuery
class is responsible for finding and reporting available media devices. To begin, simply create one:
Behind the scenes, the device query will inspect the system you are running on and find all available media devices. It will then provide all these devices as implementations of the IMediaDevice
interface.
All media devices implement the IMediaDevice
interface. To use more specific functionality, perform a type cast to the media device type you need.
Filtering for Specific Devices
The device query allows for only finding devices that meet certain conditions. This is useful for filtering for specific types of devices (like camera vs. microphone) or finding devices that support certain features (like echo-cancelling microphones). To filter devices, simply pass a predicate to the MediaDeviceQuery
constructor:
The filter is always of type Predicate<IMediaDevice>
.
See the Creating a Query section of the MediaDeviceQuery
class for more information.
Using Media Device Criteria
NatDevice includes some commonly-used filters. These can be found in the MediaDeviceCriteria
class:
Switching Devices
There are cases where you need to loop through available devices over a long period of time. A good example of this is in camera apps that allow the user to switch cameras. In such cases, the MediaDeviceQuery
can be used as a cursor for enumerating through the devices it has discovered. The query provides the current
property which returns the device at the current cursor position:
The cursor can be advanced when necessary:
See the Working with Devices section of the MediaDeviceQuery
class for more information.
The query will loop back to the first device when it has been advanced to its last device.
Last updated