23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIGURE 10-9 Previewing and recording video with the default device in the Media capture sample, Scenario 1. (The<br />

output is cropped because I needed to run the app using the Local Machine option in Visual Studio, and I didn’t<br />

think you needed to see a 1920x1200 screenshot with lots of whitespace!).<br />

Notice the Contrast and Brightness controls in Figure 10-9. Changing these will change the preview<br />

video, along with the recorded video. The sample does this through the MediaCapture.video-<br />

DeviceController object’s contrast and brightness properties, showing that these (and any others in<br />

the controller) can be adjusted dynamically. Refer to the getCameraSettings function in<br />

js/BasicCapture.js that basically wires the slider change events into a generic anonymous function to<br />

update the desired property.<br />

Selecting a Media Capture Device<br />

Looking now at Scenario 2 (js/AdvancedCapture.js), it’s more or less like Scenario 1 but it allows you to<br />

select the specific input device. Until now, everything we’ve done has simply used the default device,<br />

but you’re not limited to that, of course. You can use the Windows.Devices.Enumeration API to retrieve<br />

a list of devices within a particular device interface class; the sample uses the predefined videoCapture<br />

class:<br />

function enumerateCameras() {<br />

var cameraSelect = id("cameraSelect");<br />

deviceList = null;<br />

deviceList = new Array();<br />

while (cameraSelect.length > 0) {<br />

cameraSelect.remove(0);<br />

}<br />

//Enumerate webcams and add them to the list<br />

var deviceInfo = Windows.Devices.Enumeration.DeviceInformation;<br />

deviceInfo.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture)<br />

.done(function (devices) {<br />

458

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!