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.

vid.msInsertVideoEffect("GrayscaleTransform.GrayscaleEffect", true, null);<br />

vid.msInsertVideoEffect("InvertTransform.InvertEffect", true, null);<br />

The second parameter to msInsertVideoEffect, by the way, indicates whether the effect is required,<br />

so it’s typically true. The third is a parameter called config, which just contains additional information to<br />

pass to the effect. In the case of the geometric effects in the sample, this parameter specifies the<br />

particular variation:<br />

var effect = new Windows.Foundation.Collections.PropertySet();<br />

effect["effect"] = effectName;<br />

vid.msClearEffects();<br />

vid.msInsertVideoEffect("PolarTransform.PolarEffect", true, effect);<br />

where effectName will be either “Fisheye”, “Pinch”, or “Warp”.<br />

Audio effects, not shown in the sample, are applied the same way with msInsertAudioEffect (with<br />

the same parameters). Do note that each element can have at most two effects per media stream. A<br />

video element can have two video effects and two audio effects; an audio element can have two audio<br />

effects. If you try to add more, the methods will throw an exception. This is why it’s a good idea to call<br />

msClearEffects before inserting any others.<br />

For additional discussion on effects and other media extensions, see Using media extensions.<br />

Browsing Media Servers<br />

Many households, including my own, have one or more media servers available on the local network<br />

from which apps can play media. Getting to these servers is the purpose of the one other property in<br />

Windows.Storage.KnownFolders that we haven’t mentioned yet: mediaServerDevices. As with other<br />

known folders, this is simply a StorageFolder object through which you can then enumerate or query<br />

additional folders and files. In this case, if you call its getFoldersAsync, you’ll receive back a list of<br />

available servers, each of which is represented by another StorageFolder. From there you can use file<br />

queries, as discussed in Chapter 8, “State, Settings, Libraries, and Documents,” to search for the types of<br />

media you’re interested in or apply user-provided search criteria. An example of this can be found in the<br />

Media Server client sample.<br />

Audio Playback and Mixing<br />

As with video, the audio element provides its own playback abilities, including controls, looping, and<br />

autoplay:<br />

<br />

Again, as described earlier, the same W3C spec applies to both video and audio elements. The same<br />

code to play just the audio portion of a video is exactly what we use to play an audio file:<br />

421

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

Saved successfully!

Ooh no, something went wrong!