Today at PDC Scott Guthrie announced not only loads of cool new features for Silverlight 4, but also the release today of the Beta. So, what in the world does that have to do with CRM? Glad that you asked. We’ve got a quick demo of Dynamics CRM 4 with a Silverlight 4 tool. First a little about new Silverlight functions that allow access to web camera and microphone, then using that in CRM. Be sure to check out Silverlight Jumpstart for extensive (over 50 pages of new content) for Silverlight 4 updates, available only from the publisher. (in case anyone is wondering, no I didn’t write the code samples, my hubby did)
Web Camera / Microphone Support
Silverlight 4 now allows developers to access to the raw audio and video streams on the local machine from applications running both in and out of the browser. Using these capabilities developers can write applications including capture and collaboration using audio and video. This is built-in to the core runtime and no other special downloads are required on each machine. When the audio or video is accessed for the first time by the application the user will be prompted to approve the request. This ensures that audio and video is never accessed without the user’s knowledge preventing applications that capture silently in the background. The following is an example of the prompt the user sees when the application requests access to the devices.
You will notice in the above image the site name is displayed. This is another safeguard to ensure the user knows which site is requesting access to the devices. Access is granted to just this application and only for this session of the application. Currently there is no option to persist the user’s approval to avoid re-prompting each time the application is run. Additionally, it’s all or nothing; you don’t get to choose video or microphone. It’s a combined approval.
Users with multiple devices can select the devices they want to be the default devices using the properties on the Silverlight plug-in. This can be selected by right-clicking on a Silverlight application and going to the Webcam/Mic tab.
The following is an example of what you will see on that tab.
Developers can get access to the chosen devices using the CaptureDeviceConfiguration class. Using this class you can call the GetDefaultAudioCaptureDevice or GetDefaultVideoCaptureDevice methods to retrieve the users selected defaults. The class also has GetAvailableAudioCaptureDevices and GetAvailableVideoCaptureDevices methods that allow you to enumerate the available devices if you want more control of choosing a device besides the default.
Prior to using the devices you must request access to the device by calling the RequestDeviceAccess() method from the CaptureDeviceConfiguration class. When this method is called it is responsible for showing the user approval dialog we saw earlier. This method must be called from a user initiated event handler like the event handler for a button click event. If you call it at other times it will either not do anything or produce an error. Using the AllowedDeviceAccess property you can query if access has already been granted to the device.
The quickest way to get started using the video is to attach the capture from the device to a VideoBrush and then use the brush to paint the background of a border. The following XAML sets up the button to trigger the capture and a border that we will paint with a video brush.
<Button x:Name="btnStartvideo" Click="btnStartvideo_Click"
<Border x:Name="borderVideo" Height="200" Width="200"></Border>
Next, the following private method TurnOnVideo method is called from the handler for the click event on the button. This satisfies the requirement to be user initiated.
private void TurnOnVideo()
VideoCaptureDevice videoCap =
AudioCaptureDevice audioCap =
CaptureSource capsource = new CaptureSource();
capsource.AudioCaptureDevice = audioCap;
capsource.VideoCaptureDevice = videoCap;
VideoBrush vidBrush = new VideoBrush();
borderVideo.Background = vidBrush;
As you can see in the code above, default audio and video devices are retrieved and assigned to a CaptureSource. Access to the devices is then checked and requested if not already approved.
If access is granted the Start() method on the CaptureSource is invoked to begin capturing audio and video. Finally, the VideoBrush source is set to the CaptureSource instance and the background on the border is set to the VideoBrush.
Overtime we will probably see some very interesting applications of the audio and video support. One example that we put together was using it with Microsoft Dynamics CRM. In this example application a membership application was simulated that associated members with pictures and stored the pictures in a database. Think of a place similar to Costco, Sam’s Club or your local gym that snaps your photo for their records.
In the following image you can see how a tab has been added to the Contact form using the CRM customization capabilities.
A Silverlight 4 application is then hosted inside that tab that will provide the user experience for capturing the images. When the Start Camera button is clicked the user will be prompted to approve the access and the video feed will begin as you can see below.
The video feed will keep showing the live image updated from the web cam until stopped. The Capture button on the above application allows the user to capture one of the image frames from the capture source. The AsyncCaptureImage(..) method on the CaptureSource class allows you to request that a frame be captured and your callback invoked. The callback is then invoked and passed a WriteableBitmap representing the captured frame.
This image can then be saved back to the Dynamics CRM server and associated with the record being viewed.