23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

msInsertVideoEffect<br />

msInsertAudioEffect<br />

msClearEffects<br />

msSetMediaProtectionManager<br />

msSetVideoRectangle<br />

onMSVideoFrameStepCompleted (event)<br />

Adds or removes effects during playback (see below). All are available on video;<br />

msInsertVideoEffect is not available on audio elements.<br />

Used for DRM with both audio and video; see “Streaming from a Server and Digital Rights<br />

Management (DRM)” toward the end of this chapter.<br />

Sets the dimension of a subrectangle within a video.<br />

Occurs when the video format changes.<br />

The Source Attribute and Custom Codecs<br />

Video (and audio) elements can use the <strong>HTML</strong>5 source attribute. In web applications, multiple<br />

source elements are used to provide alternate video formats in case a client system doesn’t have<br />

the necessary codec for the primary source. Given that the list of supported formats in Windows is<br />

well known (refer again to Supported audio and video formats), this isn’t much of a concern for<br />

Windows Store apps. However, source is still useful because it can identify the specific codecs for<br />

the source:<br />

<br />

<br />

<br />

This is important when you need to provide a custom codec for your app through<br />

Windows.Media.MediaExtensionManager, outlined in the “Custom Decoders/Encovers and Scheme<br />

Handlers” section later in this chapter, as the codec identifies the extension to load for decoding. I<br />

show WebM as an example here because it’s not directly available to Store apps (though it is in<br />

Internet Explorer). When the app host running a Store app encounters the video element above, it<br />

will look for a matching decoder for the specified type.<br />

Applying a Video Effect<br />

The earlier table shows that video elements have msInsertVideoEffect and msInsertAudio-Effect<br />

methods on them. WinRT provides a built-in video stabilization effect that is easily applied to an<br />

element. This is demonstrated in Scenario 3 of the Media extensions sample, which plays the same video<br />

with and without the effect, so the stabilized one is muted:<br />

vidStab.msClearEffects();<br />

vidStab.muted = true;<br />

vidStab.msInsertVideoEffect(Windows.Media.VideoEffects.videoStabilization, true, null);<br />

Custom effects, as demonstrated in Scenario 4 of the sample, are implemented as separate<br />

dynamic-link libraries (DLLs), typically written in C++ for best performance, and are included in the app<br />

package because a Store app can install a DLL only for its own use and not for systemwide access. With<br />

the sample you’ll find DLL projects for a grayscale, invert, and geometric effects, where the latter has<br />

three options for fisheye, pinch, and warp. In the js/CustomEffect.js file you can see how these are<br />

applied, with the first parameter to msInsertVideoEffect being a string that identifies the effect as<br />

exported by the DLL (see, for instance, the InvertTransform.idl file in the InvertTransform project):<br />

420

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

Saved successfully!

Ooh no, something went wrong!