One of the exciting features of Silverlight 4 is the support for video and voice devices. The following describes how to use it:
1. List the video and voice devices:
A) The video uses system. Windows. Media. capturedeviceconfiguration. getavailablevideocapturedevices () to obtain the list of available video devices on the current computer. A collection of devices is returned.
B) The system. Windows. Media. capturedeviceconfiguration. getavailableaudiocapturedevices () method is used to obtain the list of available audio devices on the current computer. The returned result is a collection of audio and audio devices.
* The set obtained above can be placed in a ComboBox, allowing users to select and use it in practical applications.
2. Obtain the default device:
A) You can set the default audio and video devices of Silverlight. This option can be activated by right-clicking Silverlight.
B) directly obtain the default audio and video devices:
// Obtain the default audio device
System. Windows. Media. capturedeviceconfiguration. getdefaauaudiocapturedevice ();
// Obtain the default video device
System. Windows. Media. capturedeviceconfiguration. getdefavidevideocapturedevice ();
3. Obtain the streaming Coal:
A) XAML defines a rectangle for video rendering:
<Rectangle x:Name="WebcamCapture" Width="320" Height="240" Fill="White"/>
B) C # code:
// Instantiate an audio/video source
CaptureSource cs = new CaptureSource();
cs.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
cs.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
VideoBrush vidBrush = new VideoBrush();
vidBrush.SetSource(cs);
// Webcamcapture is rectangle
WebcamCapture.Fill = vidBrush;
// Obtain the user's permission to access audio and video devices
if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
{
// Start stream Extraction
_captureSource.Start();
}
. After running the video, you can extract the stream. The content of the camera will be displayed in the webcamcature rectangle in real time.